~ubuntu-branches/ubuntu/lucid/jruby/lucid

« back to all changes in this revision

Viewing changes to test/test_numeric.rb

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Delafond
  • Date: 2009-12-09 17:30:55 UTC
  • Revision ID: james.westby@ubuntu.com-20091209173055-8ffzikq1768gywux
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
 
 
3
class TestNumeric < Test::Unit::TestCase
 
4
 
 
5
  class NumericWithSomeMethods < Numeric
 
6
    def initialize(value = 0)
 
7
      @value = value
 
8
    end
 
9
    
 
10
    def expect(arg)
 
11
      @expected_arg = arg
 
12
    end
 
13
 
 
14
    def check(arg)
 
15
      raise "Expected #{@expected_arg.inspect}, but received #{arg.inspect}" unless @expected_arg == arg
 
16
    end
 
17
 
 
18
    def /(arg) check(arg); 543.21 end
 
19
    def %(arg) check(arg); 89 end
 
20
    def to_f() @value.to_f end
 
21
    def <=>(other) @value <=> other end
 
22
    def <(other) @value < other end
 
23
    def >(other) @value > other end
 
24
    def eql?(other) @value.eql?(other) end
 
25
    def to_i() @value.to_i end
 
26
  end
 
27
 
 
28
  def setup
 
29
    @a = Numeric.new
 
30
    @b = Numeric.new
 
31
  end
 
32
 
 
33
  def test_unary_plus
 
34
    assert_same @a, +@a
 
35
  end
 
36
 
 
37
  def test_unary_minus_should_raise_if_self_cannot_be_coerced_to_float
 
38
    assert_raises(TypeError) { -@a }
 
39
  end
 
40
 
 
41
  def test_unary_minus_should_coerce_to_float_and_negate_result 
 
42
    assert_equal 123.45, NumericWithSomeMethods.new(123.45).to_f
 
43
    assert_equal -123.45, -NumericWithSomeMethods.new(123.45)
 
44
  end
 
45
 
 
46
  def test_spaceship_should_return_zero_when_comparting_with_self_and_nil_otherwise
 
47
    assert_equal 0, @a <=> @a
 
48
 
 
49
    assert_nil @a <=> @b
 
50
    assert_nil @a <=> 1
 
51
    assert_nil @a <=> ""
 
52
    assert_nil @a <=> nil
 
53
  end
 
54
 
 
55
  def test_abs_should_return_self_if_bigger_than_zero_and_result_of_unitary_minus_on_self_otherwise
 
56
    assert_raises(ArgumentError) { @a.abs }
 
57
 
 
58
    positive = NumericWithSomeMethods.new(1).abs
 
59
    assert positive > 0 
 
60
    assert_same positive, positive.abs
 
61
 
 
62
    negative = NumericWithSomeMethods.new(-2)
 
63
    assert negative < 0 
 
64
    # unitary minus operator effectively returns -(self.to_f)
 
65
    assert_equal 2.0, negative.abs
 
66
    assert_equal Float, negative.abs.class
 
67
  end
 
68
 
 
69
  # ceil
 
70
  def test_ceil_should_delegate_to_self_to_f
 
71
    assert_equal 124, NumericWithSomeMethods.new(123.49).ceil
 
72
    assert_equal -123, NumericWithSomeMethods.new(-123.51).ceil
 
73
  end
 
74
 
 
75
  def test_ceil_should_raise_if_self_doesnt_implement_to_f
 
76
    assert_raises(TypeError) { @a.ceil }
 
77
  end
 
78
 
 
79
 
 
80
  def test_coerce_should_copy_argument_and_self_if_both_have_the_same_type
 
81
    assert_equal [@b, @a], @a.coerce(@b)
 
82
    assert_equal [0.9, 0.1], 0.1.coerce(0.9)
 
83
    assert_equal [0, 1], 1.coerce(0)
 
84
  end
 
85
 
 
86
  def test_coerce_should_call_float_on_self_and_arg_if_they_are_of_different_type
 
87
    bignum = 100000000000000000000000
 
88
    assert bignum.is_a?(Bignum)
 
89
    assert_equal [Float(bignum), 0.0], 0.0.coerce(bignum)
 
90
    assert 0.0.coerce(bignum).first.is_a?(Float)
 
91
    assert 0.0.coerce(bignum).last.is_a?(Float)
 
92
 
 
93
    n = NumericWithSomeMethods.new(123.45)
 
94
    assert_equal [1.0, 123.45], n.coerce(1.0)   
 
95
  end
 
96
 
 
97
  def test_coerce_should_blow_up_if_self_or_arg_cannot_be_converted_to_float_by_kernel_Float
 
98
    assert_raises(TypeError) { @a.coerce(1.0) }
 
99
    assert_raises(ArgumentError) { 1.coerce("test") }
 
100
    assert_raises(TypeError) { 1.coerce(nil) }
 
101
    assert_raises(TypeError) { 1.coerce(false) }
 
102
  end
 
103
 
 
104
  def test_div_should_raise_if_self_doesnt_implement_divison_operator
 
105
    assert_raises(NoMethodError) { @a.div(@b) }
 
106
  end
 
107
 
 
108
  def test_div_should_call_division_method_and_floor_it
 
109
    n = NumericWithSomeMethods.new
 
110
 
 
111
    # n / anything returns 543.21
 
112
    n.expect(:foo)
 
113
    assert_equal 543.21, n / :foo
 
114
    n.expect(@a)
 
115
    assert_equal 543, n.div(@a)
 
116
  end
 
117
  
 
118
  def test_divmod_should_return_result_of_div_and_mod_as_array
 
119
    n = NumericWithSomeMethods.new
 
120
    n.expect(:foo)
 
121
    # n.div(anything) returns 543, n % anything returns 89
 
122
    assert_equal [543, 89], n.divmod(:foo)
 
123
  end
 
124
  
 
125
  def test_divmod_should_calculate_div_correctly
 
126
    dividends = [-0.58, 0.58, -0.59, 0.59, -0.63, 0.63, -0.66, 0.66, -0.67, 0.67]
 
127
    divisor = 1 / 12.0
 
128
    expected_divs = [-7, 6, -8, 7, -8, 7, -8, 7, -9, 8]
 
129
    dividends.each_with_index { |dividend, idx|
 
130
      assert_equal(expected_divs[idx], dividend.divmod(divisor)[0])
 
131
    }
 
132
  end
 
133
 
 
134
  def test_divmod_should_raise_when_self_doesnt_implement_div_or_mod
 
135
    assert_raises(NoMethodError) { @a.divmod(@b) }
 
136
  end
 
137
 
 
138
  def test_eql
 
139
    assert_equal true, @a.eql?(@a)
 
140
    assert_equal false, @a.eql?(@b)
 
141
  end
 
142
  
 
143
  def test_floor_should_delegate_to_self_to_f
 
144
    assert_equal 123, NumericWithSomeMethods.new(123.51).floor
 
145
    assert_equal -124, NumericWithSomeMethods.new(-123.49).floor
 
146
  end
 
147
 
 
148
  def test_floor_should_raise_if_self_doesnt_implement_to_f
 
149
    assert_raises(TypeError) { @a.floor }
 
150
  end
 
151
 
 
152
  def test_initialize_copy_should_raise
 
153
    assert_raises(TypeError) { @a.instance_eval("initialize_copy(:foo)") }
 
154
  end
 
155
 
 
156
  def test_initialize_copy_should_be_private
 
157
    assert @a.private_methods.include?("initialize_copy")
 
158
    assert_equal false, @a.methods.include?("initialize_copy")
 
159
  end
 
160
 
 
161
  def test_integer
 
162
    assert_equal false, @a.integer?
 
163
  end
 
164
 
 
165
  def test_modulo_should_raise_if_self_doesnt_have_percent_operator
 
166
    assert_raises(NoMethodError) { @a.modulo(@b) }
 
167
  end
 
168
 
 
169
  def test_modulo_should_call_percent_operator
 
170
    n = NumericWithSomeMethods.new
 
171
    n.expect(:foo)
 
172
    # n % anything returns 89
 
173
    assert_equal 89, n.modulo(:foo)
 
174
  end
 
175
 
 
176
  def test_nonzero_should_check_equality_and_returns_self_or_nil
 
177
    assert_same @a, @a.nonzero?
 
178
    assert_nil NumericWithSomeMethods.new(0).nonzero?
 
179
    one = NumericWithSomeMethods.new(1)
 
180
    minus_one = NumericWithSomeMethods.new(1)
 
181
 
 
182
    assert_same one, one.nonzero? 
 
183
    assert_same minus_one, minus_one.nonzero?
 
184
  end
 
185
 
 
186
  def test_quo
 
187
    assert_raises(NoMethodError) { @a.quo @b }
 
188
  end
 
189
 
 
190
  def test_remainder_should_raise_if_self_doesnt_implement_modulo
 
191
    assert_raises(NoMethodError) { @a.remainder(@b) }
 
192
  end
 
193
  
 
194
  def test_remainder_should_return_modulo_if_self_and_arg_have_the_same_sign_and_modulo_minus_arg_otherwise_except_when_modulo_is_zero
 
195
    # Float doesn't override Numeric#remainder, so that's what we are testng here
 
196
    assert_equal 2.0, 5.0.remainder(3)
 
197
    assert_equal 2.0, 5.0.remainder(-3)
 
198
 
 
199
    assert_equal -2.0, -5.0.remainder(-3)
 
200
    assert_equal -2.0, -5.0.remainder(3)
 
201
 
 
202
    # special case, was a bug
 
203
    assert_equal 0.0, 4.0.remainder(2)
 
204
    assert_equal 0.0, 4.0.remainder(-2)
 
205
    assert_equal 0.0, -4.0.remainder(2)
 
206
    assert_equal 0.0, -4.0.remainder(-2)
 
207
  end
 
208
 
 
209
  def test_round_should_delegate_to_self_to_f
 
210
    assert_equal 123, NumericWithSomeMethods.new(123.49).round
 
211
    assert_equal 124, NumericWithSomeMethods.new(123.51).round
 
212
    assert_equal -123, NumericWithSomeMethods.new(-123.49).round
 
213
    assert_equal -124, NumericWithSomeMethods.new(-123.51).round
 
214
  end
 
215
 
 
216
  def test_round_should_raise_if_self_doesnt_implement_to_f
 
217
    assert_raises(TypeError) { @a.round }
 
218
  end
 
219
 
 
220
  def test_step
 
221
    # Fixnum doesn't override Numeric#step()
 
222
 
 
223
    # ends exactly at :to
 
224
    a = []
 
225
    1.step(5, 2) { |x| a << x }
 
226
    assert_equal [1, 3, 5], a
 
227
 
 
228
    # ends before :to
 
229
    a = []
 
230
    1.step(4, 2) { |x| a << x }
 
231
    assert_equal [1, 3], a
 
232
 
 
233
    # step is too big
 
234
    a = []
 
235
    1.step(4, 10) { |x| a << x }
 
236
    assert_equal [1], a
 
237
 
 
238
    # step is zero
 
239
    assert_raises(ArgumentError) { 1.step(1, 0) }
 
240
 
 
241
    # same to and from
 
242
    a = []
 
243
    1.step(1, 1) { |x| a << x }
 
244
    assert_equal [1], a
 
245
 
 
246
    # from less than to, positive step value
 
247
    a = []
 
248
    1.step(0, 1) { |x| a << x }
 
249
    assert_equal [], a
 
250
 
 
251
    # from less than to, negative step value
 
252
    a = []
 
253
    1.step(0, 1) { |x| a << x }
 
254
    assert_equal [], a
 
255
 
 
256
    # default step value of 1
 
257
    a = []
 
258
    1.step(3) { |x| a << x }
 
259
    assert_equal [1, 2, 3], a
 
260
 
 
261
  end
 
262
 
 
263
  def test_step_should_raise_if_step_is_zero
 
264
 
 
265
  end
 
266
 
 
267
 
 
268
  def test_to_int_should_call_to_i_or_raise_if_to_i_is_not_implemented
 
269
    assert_equal 123, NumericWithSomeMethods.new(123).to_int
 
270
    assert_raises(NoMethodError) { @a.to_int }
 
271
  end
 
272
 
 
273
  def test_truncate_should_delegate_to_self_to_f
 
274
    assert_equal 123, NumericWithSomeMethods.new(123.49).truncate
 
275
    assert_equal 123, NumericWithSomeMethods.new(123.51).truncate
 
276
    assert_equal -123, NumericWithSomeMethods.new(-123.49).truncate
 
277
    assert_equal -123, NumericWithSomeMethods.new(-123.51).truncate
 
278
  end
 
279
 
 
280
  def test_truncate_should_raise_if_self_doesnt_implement_to_f
 
281
    assert_raises(TypeError) { @a.truncate }
 
282
  end
 
283
 
 
284
  def test_zero_should_check_equality
 
285
    assert_equal false, @a.zero?
 
286
    assert_equal true, NumericWithSomeMethods.new(0).zero?
 
287
    assert_equal false, NumericWithSomeMethods.new(1).zero?
 
288
    assert_equal false, NumericWithSomeMethods.new(-1).zero?
 
289
  end
 
290
 
 
291
end
 
292
require 'test/unit'
 
293
 
 
294
class TestNumeric < Test::Unit::TestCase
 
295
 
 
296
  class NumericWithSomeMethods < Numeric
 
297
    def initialize(value = 0)
 
298
      @value = value
 
299
    end
 
300
    
 
301
    def expect(arg)
 
302
      @expected_arg = arg
 
303
    end
 
304
 
 
305
    def check(arg)
 
306
      raise "Expected #{@expected_arg.inspect}, but received #{arg.inspect}" unless @expected_arg == arg
 
307
    end
 
308
 
 
309
    def /(arg) check(arg); 543.21 end
 
310
    def %(arg) check(arg); 89 end
 
311
    def to_f() @value.to_f end
 
312
    def <=>(other) @value <=> other end
 
313
    def <(other) @value < other end
 
314
    def >(other) @value > other end
 
315
    def eql?(other) @value.eql?(other) end
 
316
    def to_i() @value.to_i end
 
317
  end
 
318
 
 
319
  def setup
 
320
    @a = Numeric.new
 
321
    @b = Numeric.new
 
322
  end
 
323
 
 
324
  def test_unary_plus
 
325
    assert_same @a, +@a
 
326
  end
 
327
 
 
328
  def test_unary_minus_should_raise_if_self_cannot_be_coerced_to_float
 
329
    assert_raises(TypeError) { -@a }
 
330
  end
 
331
 
 
332
  def test_unary_minus_should_coerce_to_float_and_negate_result 
 
333
    assert_equal 123.45, NumericWithSomeMethods.new(123.45).to_f
 
334
    assert_equal -123.45, -NumericWithSomeMethods.new(123.45)
 
335
  end
 
336
 
 
337
  def test_spaceship_should_return_zero_when_comparting_with_self_and_nil_otherwise
 
338
    assert_equal 0, @a <=> @a
 
339
 
 
340
    assert_nil @a <=> @b
 
341
    assert_nil @a <=> 1
 
342
    assert_nil @a <=> ""
 
343
    assert_nil @a <=> nil
 
344
  end
 
345
 
 
346
  def test_abs_should_return_self_if_bigger_than_zero_and_result_of_unitary_minus_on_self_otherwise
 
347
    assert_raises(ArgumentError) { @a.abs }
 
348
 
 
349
    positive = NumericWithSomeMethods.new(1).abs
 
350
    assert positive > 0 
 
351
    assert_same positive, positive.abs
 
352
 
 
353
    negative = NumericWithSomeMethods.new(-2)
 
354
    assert negative < 0 
 
355
    # unitary minus operator effectively returns -(self.to_f)
 
356
    assert_equal 2.0, negative.abs
 
357
    assert_equal Float, negative.abs.class
 
358
  end
 
359
 
 
360
  # ceil
 
361
  def test_ceil_should_delegate_to_self_to_f
 
362
    assert_equal 124, NumericWithSomeMethods.new(123.49).ceil
 
363
    assert_equal -123, NumericWithSomeMethods.new(-123.51).ceil
 
364
  end
 
365
 
 
366
  def test_ceil_should_raise_if_self_doesnt_implement_to_f
 
367
    assert_raises(TypeError) { @a.ceil }
 
368
  end
 
369
 
 
370
 
 
371
  def test_coerce_should_copy_argument_and_self_if_both_have_the_same_type
 
372
    assert_equal [@b, @a], @a.coerce(@b)
 
373
    assert_equal [0.9, 0.1], 0.1.coerce(0.9)
 
374
    assert_equal [0, 1], 1.coerce(0)
 
375
  end
 
376
 
 
377
  def test_coerce_should_call_float_on_self_and_arg_if_they_are_of_different_type
 
378
    bignum = 100000000000000000000000
 
379
    assert bignum.is_a?(Bignum)
 
380
    assert_equal [Float(bignum), 0.0], 0.0.coerce(bignum)
 
381
    assert 0.0.coerce(bignum).first.is_a?(Float)
 
382
    assert 0.0.coerce(bignum).last.is_a?(Float)
 
383
 
 
384
    n = NumericWithSomeMethods.new(123.45)
 
385
    assert_equal [1.0, 123.45], n.coerce(1.0)   
 
386
  end
 
387
 
 
388
  def test_coerce_should_blow_up_if_self_or_arg_cannot_be_converted_to_float_by_kernel_Float
 
389
    assert_raises(TypeError) { @a.coerce(1.0) }
 
390
    assert_raises(ArgumentError) { 1.coerce("test") }
 
391
    assert_raises(TypeError) { 1.coerce(nil) }
 
392
    assert_raises(TypeError) { 1.coerce(false) }
 
393
  end
 
394
 
 
395
  def test_div_should_raise_if_self_doesnt_implement_divison_operator
 
396
    assert_raises(NoMethodError) { @a.div(@b) }
 
397
  end
 
398
 
 
399
  def test_div_should_call_division_method_and_floor_it
 
400
    n = NumericWithSomeMethods.new
 
401
 
 
402
    # n / anything returns 543.21
 
403
    n.expect(:foo)
 
404
    assert_equal 543.21, n / :foo
 
405
    n.expect(@a)
 
406
    assert_equal 543, n.div(@a)
 
407
  end
 
408
  
 
409
  def test_divmod_should_return_result_of_div_and_mod_as_array
 
410
    n = NumericWithSomeMethods.new
 
411
    n.expect(:foo)
 
412
    # n.div(anything) returns 543, n % anything returns 89
 
413
    assert_equal [543, 89], n.divmod(:foo)
 
414
  end
 
415
 
 
416
  def test_divmod_should_raise_when_self_doesnt_implement_div_or_mod
 
417
    assert_raises(NoMethodError) { @a.divmod(@b) }
 
418
  end
 
419
 
 
420
  def test_eql
 
421
    assert_equal true, @a.eql?(@a)
 
422
    assert_equal false, @a.eql?(@b)
 
423
  end
 
424
  
 
425
  def test_floor_should_delegate_to_self_to_f
 
426
    assert_equal 123, NumericWithSomeMethods.new(123.51).floor
 
427
    assert_equal -124, NumericWithSomeMethods.new(-123.49).floor
 
428
  end
 
429
 
 
430
  def test_floor_should_raise_if_self_doesnt_implement_to_f
 
431
    assert_raises(TypeError) { @a.floor }
 
432
  end
 
433
 
 
434
  def test_initialize_copy_should_raise
 
435
    assert_raises(TypeError) { @a.instance_eval("initialize_copy(:foo)") }
 
436
  end
 
437
 
 
438
  def test_initialize_copy_should_be_private
 
439
    assert @a.private_methods.include?("initialize_copy")
 
440
    assert_equal false, @a.methods.include?("initialize_copy")
 
441
  end
 
442
 
 
443
  def test_integer
 
444
    assert_equal false, @a.integer?
 
445
  end
 
446
 
 
447
  def test_modulo_should_raise_if_self_doesnt_have_percent_operator
 
448
    assert_raises(NoMethodError) { @a.modulo(@b) }
 
449
  end
 
450
 
 
451
  def test_modulo_should_call_percent_operator
 
452
    n = NumericWithSomeMethods.new
 
453
    n.expect(:foo)
 
454
    # n % anything returns 89
 
455
    assert_equal 89, n.modulo(:foo)
 
456
  end
 
457
 
 
458
  def test_nonzero_should_check_equality_and_returns_self_or_nil
 
459
    assert_same @a, @a.nonzero?
 
460
    assert_nil NumericWithSomeMethods.new(0).nonzero?
 
461
    one = NumericWithSomeMethods.new(1)
 
462
    minus_one = NumericWithSomeMethods.new(1)
 
463
 
 
464
    assert_same one, one.nonzero? 
 
465
    assert_same minus_one, minus_one.nonzero?
 
466
  end
 
467
 
 
468
  def test_quo
 
469
    assert_raises(NoMethodError) { @a.quo @b }
 
470
  end
 
471
 
 
472
  def test_remainder_should_raise_if_self_doesnt_implement_modulo
 
473
    assert_raises(NoMethodError) { @a.remainder(@b) }
 
474
  end
 
475
  
 
476
  def test_remainder_should_return_modulo_if_self_and_arg_have_the_same_sign_and_modulo_minus_arg_otherwise_except_when_modulo_is_zero
 
477
    # Float doesn't override Numeric#remainder, so that's what we are testng here
 
478
    assert_equal 2.0, 5.0.remainder(3)
 
479
    assert_equal 2.0, 5.0.remainder(-3)
 
480
 
 
481
    assert_equal -2.0, -5.0.remainder(-3)
 
482
    assert_equal -2.0, -5.0.remainder(3)
 
483
 
 
484
    # special case, was a bug
 
485
    assert_equal 0.0, 4.0.remainder(2)
 
486
    assert_equal 0.0, 4.0.remainder(-2)
 
487
    assert_equal 0.0, -4.0.remainder(2)
 
488
    assert_equal 0.0, -4.0.remainder(-2)
 
489
  end
 
490
 
 
491
  def test_round_should_delegate_to_self_to_f
 
492
    assert_equal 123, NumericWithSomeMethods.new(123.49).round
 
493
    assert_equal 124, NumericWithSomeMethods.new(123.51).round
 
494
    assert_equal -123, NumericWithSomeMethods.new(-123.49).round
 
495
    assert_equal -124, NumericWithSomeMethods.new(-123.51).round
 
496
  end
 
497
 
 
498
  def test_round_should_raise_if_self_doesnt_implement_to_f
 
499
    assert_raises(TypeError) { @a.round }
 
500
  end
 
501
 
 
502
  def test_step
 
503
    # Fixnum doesn't override Numeric#step()
 
504
 
 
505
    # ends exactly at :to
 
506
    a = []
 
507
    1.step(5, 2) { |x| a << x }
 
508
    assert_equal [1, 3, 5], a
 
509
 
 
510
    # ends before :to
 
511
    a = []
 
512
    1.step(4, 2) { |x| a << x }
 
513
    assert_equal [1, 3], a
 
514
 
 
515
    # step is too big
 
516
    a = []
 
517
    1.step(4, 10) { |x| a << x }
 
518
    assert_equal [1], a
 
519
 
 
520
    # step is zero
 
521
    assert_raises(ArgumentError) { 1.step(1, 0) }
 
522
 
 
523
    # same to and from
 
524
    a = []
 
525
    1.step(1, 1) { |x| a << x }
 
526
    assert_equal [1], a
 
527
 
 
528
    # from less than to, positive step value
 
529
    a = []
 
530
    1.step(0, 1) { |x| a << x }
 
531
    assert_equal [], a
 
532
 
 
533
    # from less than to, negative step value
 
534
    a = []
 
535
    1.step(0, 1) { |x| a << x }
 
536
    assert_equal [], a
 
537
 
 
538
    # default step value of 1
 
539
    a = []
 
540
    1.step(3) { |x| a << x }
 
541
    assert_equal [1, 2, 3], a
 
542
 
 
543
  end
 
544
 
 
545
  def test_step_should_raise_if_step_is_zero
 
546
 
 
547
  end
 
548
 
 
549
 
 
550
  def test_to_int_should_call_to_i_or_raise_if_to_i_is_not_implemented
 
551
    assert_equal 123, NumericWithSomeMethods.new(123).to_int
 
552
    assert_raises(NoMethodError) { @a.to_int }
 
553
  end
 
554
 
 
555
  def test_truncate_should_delegate_to_self_to_f
 
556
    assert_equal 123, NumericWithSomeMethods.new(123.49).truncate
 
557
    assert_equal 123, NumericWithSomeMethods.new(123.51).truncate
 
558
    assert_equal -123, NumericWithSomeMethods.new(-123.49).truncate
 
559
    assert_equal -123, NumericWithSomeMethods.new(-123.51).truncate
 
560
  end
 
561
 
 
562
  def test_truncate_should_raise_if_self_doesnt_implement_to_f
 
563
    assert_raises(TypeError) { @a.truncate }
 
564
  end
 
565
 
 
566
  def test_zero_should_check_equality
 
567
    assert_equal false, @a.zero?
 
568
    assert_equal true, NumericWithSomeMethods.new(0).zero?
 
569
    assert_equal false, NumericWithSomeMethods.new(1).zero?
 
570
    assert_equal false, NumericWithSomeMethods.new(-1).zero?
 
571
  end
 
572
 
 
573
end