diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-13 13:31:41 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-13 13:31:41 +0000 |
commit | 3cf28c2caa1d0edbd78082bfe7b6c01172bb861f (patch) | |
tree | 53789d9366f0c18d7086859f19a1995a0740709d | |
parent | 71467c78c2923115649ce93550352fd4f9d550e5 (diff) | |
download | ruby-3cf28c2caa1d0edbd78082bfe7b6c01172bb861f.tar.gz |
add assertions using equations taken from Hacker's Delight.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_integer.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 865e0c5d6f..1bce4102c7 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -65,6 +65,10 @@ class TestInteger < Test::Unit::TestCase c = a + b assert_equal(a, c - b, "(#{a} + #{b}) - #{b}") assert_equal(b, c - a, "(#{a} + #{b}) - #{a}") + assert_equal(a-~b-1, c, "#{a} + #{b}") # Hacker's Delight + assert_equal((a^b)+2*(a&b), c, "#{a} + #{b}") # Hacker's Delight + assert_equal((a|b)+(a&b), c, "#{a} + #{b}") # Hacker's Delight + assert_equal(2*(a|b)-(a^b), c, "#{a} + #{b}") # Hacker's Delight } } end @@ -75,6 +79,10 @@ class TestInteger < Test::Unit::TestCase c = a - b assert_equal(a, c + b, "(#{a} - #{b}) + #{b}") assert_equal(-b, c - a, "(#{a} - #{b}) - #{a}") + assert_equal(a+~b+1, c, "#{a} - #{b}") # Hacker's Delight + assert_equal((a^b)-2*(b&~a), c, "#{a} - #{b}") # Hacker's Delight + assert_equal((a&~b)-(b&~a), c, "#{a} - #{b}") # Hacker's Delight + assert_equal(2*(a&~b)-(a^b), c, "#{a} - #{b}") # Hacker's Delight } } end @@ -121,6 +129,8 @@ class TestInteger < Test::Unit::TestCase def test_not VS.each {|a| b = ~a + assert_equal(-1 ^ a, b, "~#{a}") + assert_equal(-a-1, b, "~#{a}") # Hacker's Delight assert_equal(0, a & b, "#{a} & ~#{a}") assert_equal(-1, a | b, "#{a} | ~#{a}") } @@ -130,6 +140,8 @@ class TestInteger < Test::Unit::TestCase VS.each {|a| VS.each {|b| c = a | b + assert_equal(a + b - (a&b), c, "#{a} | #{b}") + assert_equal((a & ~b) + b, c, "#{a} | #{b}") # Hacker's Delight assert_equal(-1, c | ~a, "(#{a} | #{b}) | ~#{a})") assert_equal(-1, c | ~b, "(#{a} | #{b}) | ~#{b})") } @@ -140,6 +152,8 @@ class TestInteger < Test::Unit::TestCase VS.each {|a| VS.each {|b| c = a & b + assert_equal(a + b - (a|b), c, "#{a} & #{b}") + assert_equal((~a | b) - ~a, c, "#{a} & #{b}") # Hacker's Delight assert_equal(0, c & ~a, "(#{a} & #{b}) & ~#{a}") assert_equal(0, c & ~b, "(#{a} & #{b}) & ~#{b}") } @@ -150,6 +164,7 @@ class TestInteger < Test::Unit::TestCase VS.each {|a| VS.each {|b| c = a ^ b + assert_equal((a|b)-(a&b), c, "#{a} ^ #{b}") # Hacker's Delight assert_equal(b, c ^ a, "(#{a} ^ #{b}) ^ #{a}") assert_equal(a, c ^ b, "(#{a} ^ #{b}) ^ #{b}") } |