-
-
Notifications
You must be signed in to change notification settings - Fork 921
/
test_bignum.rb
46 lines (39 loc) · 1.26 KB
/
test_bignum.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'test/unit'
class TestBignum < Test::Unit::TestCase
# others tested in FixnumBignumAutoconversion test
def setup
@big = 12 ** 56
@big2 = 341 ** 43
# Inf = 1/0.0
end
def test_bignum_exceptions_behave_as_expected
assert_raise(ArgumentError){@big.to_s(-1)}
assert_raise(ArgumentError){@big.to_s(37)}
assert_raise(TypeError){@big.coerce(0.0)}
assert_raise(FloatDomainError){@big.divmod(0.0)}
assert_raise(ZeroDivisionError){@big.divmod(0)}
assert_raise(ZeroDivisionError){@big.remainder(0)}
assert_raise(ZeroDivisionError){@big.modulo(0)}
end
def test_sufficiently_large_number_should_be_bignum
assert(@big.class,Bignum)
end
def test_math_operations_on_bignum_with_float_should_produce_float
assert((100**50/2.0).class,Float)
assert((100**50+2.0).class,Float)
assert((100**50-2.0).class,Float)
assert((100**50*2.0).class,Float)
assert((100**50%2.0).class,Float)
end
def test_bignum_should_respond_to_array_operator
assert_equal(@big2[0],1)
assert_equal(@big2[1],0)
assert_equal(@big[-1],0)
assert_equal(-(@big2)[0],-1)
assert_equal(-(@big2)[1],0)
end
def test_bignum_aref_with_bignum_arg_no_exception
assert_equal(0, (2**64)[2**32])
end
# more to come
end