test/test_numeral.rb in numerals-0.0.0 vs test/test_numeral.rb in numerals-0.1.0

- old
+ new

@@ -194,10 +194,12 @@ assert_equal Numeral[3, point: -3, repeat: 0], Numeral.from_quotient(1, 3000) assert_equal Numeral[7,2,1,4, point: 1, repeat: 2, sign: -1], Numeral.from_quotient(-3571, 495) assert_equal Numeral[1,2,3,4,5,4,5, point: 1, repeat: 1], Numeral.from_quotient(1234544, 999999) assert_equal Numeral[1,2,3,4,5,4,5,2,3,4,5, point: 1, repeat: 9], Numeral.from_quotient(678999879, 550000000) assert_equal Numeral[1,2,3,4,5,4,5,2,3,4,5, point: 1, repeat: 9], Numeral.from_quotient(678999879, 550000000) + assert_equal Numeral[1, 1, point: -3, repeat: -2, base: 2], + Numeral.from_quotient(Rational(1,10), base:2) end def test_numeral_to_quotient assert_equal [7, 3], Numeral[2, 3, point: 1, repeat: 1].to_quotient assert_equal [-7, 3], Numeral[2, 3, point: 1, repeat: 1, sign: -1].to_quotient @@ -243,11 +245,22 @@ assert_equal Numeral[1,2,3,4,5,4,5,2,3,4,5, point: 1, repeat: 9], Numeral[1,2,3,4,5,4,5,2,3,4,5,4,5, point: 1, repeat: 11] assert_equal Numeral[1,2,3,4,5,4,5,2,3,4,5,4,5, point: 1, repeat: 9], Numeral[1,2,3,4,5,4,5,2,3,4,5,4,5, point: 1, repeat: 9] assert_equal Numeral.integer(1), Numeral[9, point: 0, repeat: 0] assert_equal Numeral[2, point: 0], Numeral[1,9, point: 0, repeat: 1] + end + def test_partial_unneeded_rep_normalization + numeral = Numeral[1, 0, 1, 1, 1, 0, base: 2, point: 2, repeat: 2] + assert_equal Numeral[1, 0, 1, 1, 1, base: 2, point: 2, repeat: 1, normalize: false], numeral + assert_equal Numeral[1,2,3,4,5, point: 1, repeat: 3, normalize: false], Numeral[1,2,3,4,5, point: 1, repeat: 3] + assert_equal Numeral[1,2,3,4,5, point: 1, repeat: 3, normalize: false], Numeral[1,2,3,4,5,4, point: 1, repeat: 4] + assert_equal Numeral[1,2,3,4,5, point: 1, repeat: 3, normalize: false], Numeral[1,2,3,4,5,4,5, point: 1, repeat: 5] + assert_equal Numeral[1,2,3,4,5,6,7,8, point: 1, repeat: 3, normalize: false], Numeral[1,2,3,4,5,6,7,8,4, point: 1, repeat: 4] + assert_equal Numeral[1,2,3,4,5,6,7,8, point: 1, repeat: 3, normalize: false], Numeral[1,2,3,4,5,6,7,8,4,5, point: 1, repeat: 5] + assert_equal Numeral[1,2,3,4,5,6,7,8, point: 1, repeat: 3, normalize: false], Numeral[1,2,3,4,5,6,7,8,4,5,6, point: 1, repeat: 6] + assert_equal Numeral[1,2,3,4,5,6,7,8,4,6, point: 1, repeat: 5, normalize: false], Numeral[1,2,3,4,5,6,7,8,4,6, point: 1, repeat: 5] end def test_quotient_conversion [[7,3], [1,3], [10,3], [100,3], [1000,3], [1000000000000, 3], [3,1], [3,1000], [1, 30], [1, 300], [1, 3000], @@ -359,8 +372,30 @@ assert_equal 1, exact.point assert_equal exact.digits.size, exact.repeat exact = exact.exact assert exact.exact? assert_equal Digits[1,2,3,4,5], exact.digits + end + + def test_digit_value_at + n = Numeral[1,2,3, repeat: -10, point: 1] + (-20...0).each do |i| + assert_equal 0, n.digit_value_at(i) + end + assert_equal 1, n.digit_value_at(0) + assert_equal 2, n.digit_value_at(1) + assert_equal 3, n.digit_value_at(2) + (3...13).each do |i| + assert_equal 0, n.digit_value_at(i) + end + assert_equal 1, n.digit_value_at(13) + assert_equal 2, n.digit_value_at(14) + assert_equal 3, n.digit_value_at(15) + (16...26).each do |i| + assert_equal 0, n.digit_value_at(i) + end + assert_equal 1, n.digit_value_at(26) + assert_equal 2, n.digit_value_at(27) + assert_equal 3, n.digit_value_at(28) end end