Permalink
Browse files

- Fixed inconsistency in refute_in_delta/epsilon. I double negatived …

…my logic. (nettsundere)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8396]
  • Loading branch information...
1 parent 5ba6229 commit 9d1508d320e6d112cbe7d247b3ae7426d67a9ab2 @zenspider zenspider committed Apr 11, 2013
Showing with 46 additions and 26 deletions.
  1. +5 −3 lib/minitest/unit.rb
  2. +12 −12 test/minitest/test_minitest_spec.rb
  3. +29 −11 test/minitest/test_minitest_unit.rb
View
@@ -231,7 +231,9 @@ def assert_equal exp, act, msg = nil
def assert_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs
- msg = message(msg) { "Expected |#{exp} - #{act}| (#{n}) to be < #{delta}"}
+ msg = message(msg) {
+ "Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
+ }
assert delta >= n, msg
end
@@ -595,9 +597,9 @@ def refute_equal exp, act, msg = nil
def refute_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs
msg = message(msg) {
- "Expected |#{exp} - #{act}| (#{n}) to not be < #{delta}"
+ "Expected |#{exp} - #{act}| (#{n}) to not be <= #{delta}"
}
- refute delta > n, msg
+ refute delta >= n, msg
end
##
@@ -199,16 +199,16 @@ def assert_triggered expected = "blah", klass = MiniTest::Assertion
24.wont_be_close_to(42).must_equal false
- assert_triggered "Expected |42 - 42.0| (0.0) to not be < 0.001." do
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
(6 * 7.0).wont_be_close_to 42
end
x = maglev? ? "1.0000000000000001e-05" : "1.0e-05"
- assert_triggered "Expected |42 - 42.0| (0.0) to not be < #{x}." do
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
(6 * 7.0).wont_be_close_to 42, 0.00001
end
- assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be < #{x}." do
+ assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
(6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
end
end
@@ -219,16 +219,16 @@ def assert_triggered expected = "blah", klass = MiniTest::Assertion
24.wont_be_within_epsilon(42).must_equal false
x = maglev? ? "0.042000000000000003" : "0.042"
- assert_triggered "Expected |42 - 42.0| (0.0) to not be < #{x}." do
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
(6 * 7.0).wont_be_within_epsilon 42
end
x = maglev? ? "0.00042000000000000002" : "0.00042"
- assert_triggered "Expected |42 - 42.0| (0.0) to not be < #{x}." do
+ assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
(6 * 7.0).wont_be_within_epsilon 42, 0.00001
end
- assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be < #{x}." do
+ assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
(6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
end
end
@@ -238,16 +238,16 @@ def assert_triggered expected = "blah", klass = MiniTest::Assertion
(6.0 * 7).must_be_close_to(42.0).must_equal true
- assert_triggered "Expected |0.0 - 0.01| (0.01) to be < 0.001." do
+ assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
(1.0 / 100).must_be_close_to 0.0
end
x = maglev? ? "9.9999999999999995e-07" : "1.0e-06"
- assert_triggered "Expected |0.0 - 0.001| (0.001) to be < #{x}." do
+ assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
(1.0 / 1000).must_be_close_to 0.0, 0.000001
end
- assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be < #{x}." do
+ assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= #{x}." do
(1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
end
end
@@ -257,15 +257,15 @@ def assert_triggered expected = "blah", klass = MiniTest::Assertion
(6.0 * 7).must_be_within_epsilon(42.0).must_equal true
- assert_triggered "Expected |0.0 - 0.01| (0.01) to be < 0.0." do
+ assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
(1.0 / 100).must_be_within_epsilon 0.0
end
- assert_triggered "Expected |0.0 - 0.001| (0.001) to be < 0.0." do
+ assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= 0.0." do
(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
end
- assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be < 0.0." do
+ assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= 0.0." do
(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
end
end
@@ -921,9 +921,17 @@ def test_assert_in_delta
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
end
+ def test_delta_consistency
+ @tc.assert_in_delta 0, 1, 1
+
+ util_assert_triggered "Expected |0 - 1| (1) to not be <= 1." do
+ @tc.refute_in_delta 0, 1, 1
+ end
+ end
+
def test_assert_in_delta_triggered
- x = maglev? ? "9.9999999999999995e-07" : "1.0e-06"
- util_assert_triggered "Expected |0.0 - 0.001| (0.001) to be < #{x}." do
+ x = maglev? ? "9.999999xxxe-07" : "1.0e-06"
+ util_assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
end
end
@@ -945,16 +953,25 @@ def test_assert_in_epsilon
@tc.assert_in_epsilon(-10000, -9991)
end
+ def test_epsilon_consistency
+ @tc.assert_in_epsilon 1.0, 1.001
+
+ msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."
+ util_assert_triggered msg do
+ @tc.refute_in_epsilon 1.0, 1.001
+ end
+ end
+
def test_assert_in_epsilon_triggered
- util_assert_triggered 'Expected |10000 - 9990| (10) to be < 9.99.' do
+ util_assert_triggered 'Expected |10000 - 9990| (10) to be <= 9.99.' do
@tc.assert_in_epsilon 10000, 9990
end
end
def test_assert_in_epsilon_triggered_negative_case
- x = (RUBY18 and not maglev?) ? "0.1" : "0.10000000000000009"
- y = maglev? ? "0.10000000000000001" : "0.1"
- util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be < #{y}." do
+ x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
+ y = maglev? ? "0.100000xxx" : "0.1"
+ util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
@tc.assert_in_epsilon(-1.1, -1, 0.1)
end
end
@@ -1500,19 +1517,19 @@ def test_refute_in_delta
end
def test_refute_in_delta_triggered
- x = maglev? ? "0.10000000000000001" : "0.1"
- util_assert_triggered "Expected |0.0 - 0.001| (0.001) to not be < #{x}." do
+ x = maglev? ? "0.100000xxx" : "0.1"
+ util_assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
end
end
def test_refute_in_epsilon
- @tc.refute_in_epsilon 10000, 9990
+ @tc.refute_in_epsilon 10000, 9990-1
end
def test_refute_in_epsilon_triggered
- util_assert_triggered 'Expected |10000 - 9991| (9) to not be < 10.0.' do
- @tc.refute_in_epsilon 10000, 9991
+ util_assert_triggered 'Expected |10000 - 9990| (10) to not be <= 10.0.' do
+ @tc.refute_in_epsilon 10000, 9990
fail
end
end
@@ -1711,6 +1728,7 @@ def util_assert_triggered expected, klass = MiniTest::Assertion
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
msg.gsub!(/\(oid=[-0-9]+\)/, '(oid=N)')
+ msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
assert_equal expected, msg
end

0 comments on commit 9d1508d

Please sign in to comment.