Class: StringNumeralTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
MoreMath
Defined in:
tests/string_numeral_test.rb

Constant Summary

Constants included from MoreMath

MoreMath::Infinity, MoreMath::STD_NORMAL_DISTRIBUTION, MoreMath::VERSION, MoreMath::VERSION_ARRAY, MoreMath::VERSION_BUILD, MoreMath::VERSION_MAJOR, MoreMath::VERSION_MINOR

Instance Method Summary collapse

Instance Method Details

#test_arithmeticsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'tests/string_numeral_test.rb', line 46

def test_arithmetics
  s = StringNumeral.from('abc', 'abc')
  assert_equal 54, 3 * s
  assert_equal 54, s * 3
  assert_equal 6, s / 3
  assert_equal 3, 54 / s
  assert_equal 19, s + 1
  assert_equal 19, 1 + s
  assert_equal 17, s - 1
  assert_equal 1, 19 - s
  assert_equal 324, s ** 2
  assert_equal 0, s % 2
  assert_equal 9, s >> 1
  assert_equal 36, s << 1
  assert_equal 2, s ^ 16
  assert_equal 19, s | 1
  assert_equal 2, s & 2
  assert_equal 1, s[1]
end

#test_displayingObject



20
21
22
23
24
25
26
27
28
# File 'tests/string_numeral_test.rb', line 20

def test_displaying
  s = StringNumeral.from('abc')
  assert_equal 'abc', s.string
  assert_equal 'abc', s.to_s
  assert_equal 'abc', s.to_str
  assert_equal 731, s.to_i
  assert_equal 731, s.to_int
  assert_equal '#<MoreMath::StringNumeral: "abc" 731>', s.inspect
end

#test_equalityObject



9
10
11
12
13
14
15
16
17
18
# File 'tests/string_numeral_test.rb', line 9

def test_equality
  s = StringNumeral.from('abc')
  t = 731.to_string_numeral
  u = StringNumeral(:abc)
  assert_equal t, s
  assert_equal 'abc', s
  assert_equal u, t
  assert_equal s, u
  assert_equal s.hash, t.hash
end

#test_predObject



38
39
40
41
42
43
44
# File 'tests/string_numeral_test.rb', line 38

def test_pred
  s = StringNumeral.from('aca', 'abc')
  t = s.pred
  assert_equal 'abc', t.string
  s.pred!
  assert_equal 'abc', s.string
end

#test_succObject



30
31
32
33
34
35
36
# File 'tests/string_numeral_test.rb', line 30

def test_succ
  s = StringNumeral.from('abc', 'abc')
  t = s.succ
  assert_equal 'aca', t.string
  s.succ!
  assert_equal 'aca', s.string
end