Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 3c883bdd1700f23da29fd8f534ee366855c0a6a5 1 parent 1edeb9a
@akr akr authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 test/ruby/test_integer.rb
View
17 test/ruby/test_integer.rb
@@ -83,6 +83,8 @@ class TestInteger < Test::Unit::TestCase
0x10000000000000001,
]
+ #VS.map! {|v| 0x40000000.coerce(v)[0] }
+
def test_aref
VS.each {|a|
100.times {|i|
@@ -97,7 +99,6 @@ def test_plus
c = a + b
assert_equal(b + a, 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
@@ -125,7 +126,6 @@ def test_mult
VS.each {|b|
c = a * b
assert_equal(b * a, c, "#{a} * #{b}")
- assert_equal(a, c / b, "(#{a} * #{b}) / #{b}") if b != 0
assert_equal(b, c / a, "(#{a} * #{b}) / #{a}") if a != 0
assert_equal(a.abs * b.abs, (a * b).abs, "(#{a} * #{b}).abs")
assert_equal((a-100)*(b-100)+(a-100)*100+(b-100)*100+10000, c, "#{a} * #{b}")
@@ -158,6 +158,11 @@ def test_pow
d = 1
b.times { d *= a }
assert_equal(d, c, "(#{a}) ** #{b}")
+ if a != 0
+ d = c
+ b.times { d /= a }
+ assert_equal(1, d, "((#{a}) ** #{b}) ** (-#{b})")
+ end
}
}
end
@@ -180,7 +185,6 @@ def test_or
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})")
}
}
end
@@ -193,7 +197,6 @@ def test_and
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}")
}
}
end
@@ -205,7 +208,6 @@ def test_xor
assert_equal(b ^ a, 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}")
}
}
end
@@ -245,6 +247,7 @@ def test_succ
b = a.succ
assert_equal(a+1, b, "(#{a}).succ")
assert_equal(a, b.pred, "(#{a}).succ.pred")
+ assert_equal(a, b-1, "(#{a}).succ - 1")
}
end
@@ -253,6 +256,7 @@ def test_pred
b = a.pred
assert_equal(a-1, b, "(#{a}).pred")
assert_equal(a, b.succ, "(#{a}).pred.succ")
+ assert_equal(a, b + 1, "(#{a}).pred + 1")
}
end
@@ -267,6 +271,8 @@ def test_unary_minus
VS.each {|a|
b = -a
assert_equal(0-a, b, "-(#{a})")
+ assert_equal(~a+1, b, "-(#{a})")
+ assert_equal(0, a+b, "#{a}+(-(#{a}))")
}
end
@@ -286,6 +292,7 @@ def test_eq
VS.each_with_index {|a, i|
VS.each_with_index {|b, j|
c = a == b
+ assert_equal(b == a, c, "#{a} == #{b}")
assert_equal(i == j, c, "#{a} == #{b}")
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.