Skip to content

Commit

Permalink
- Fixed assert_in_epsilon when both args are negative. (tamc)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 7105]
  • Loading branch information
zenspider committed Feb 29, 2012
1 parent dda4630 commit cb593b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/minitest/unit.rb
Expand Up @@ -233,7 +233,7 @@ def assert_in_delta exp, act, delta = 0.001, msg = nil
# error less than +epsilon+.

def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
assert_in_delta a, b, [a, b].min * epsilon, msg
assert_in_delta a, b, [a.abs, b.abs].min * epsilon, msg
end

##
Expand Down
14 changes: 13 additions & 1 deletion test/test_minitest_unit.rb
Expand Up @@ -661,6 +661,8 @@ def util_expand_bt bt
end

class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
RUBY18 = ! defined? Encoding

def setup
super

Expand Down Expand Up @@ -847,7 +849,7 @@ def test_assert_in_delta_triggered
end

def test_assert_in_epsilon
@assertion_count = 8
@assertion_count = 10

@tc.assert_in_epsilon 10000, 9991
@tc.assert_in_epsilon 9991, 10000
Expand All @@ -858,6 +860,9 @@ def test_assert_in_epsilon
@tc.assert_in_epsilon 9999.1, 10000, 0.0001
@tc.assert_in_epsilon 1.0, 1.0001, 0.0001
@tc.assert_in_epsilon 1.0001, 1.0, 0.0001

@tc.assert_in_epsilon(-1, -1)
@tc.assert_in_epsilon(-10000, -9991)
end

def test_assert_in_epsilon_triggered
Expand All @@ -866,6 +871,13 @@ def test_assert_in_epsilon_triggered
end
end

def test_assert_in_epsilon_triggered_negative_case
x = RUBY18 ? "0.1" : "0.10000000000000009"
util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be < 0.1." do
@tc.assert_in_epsilon(-1.1, -1, 0.1)
end
end

def test_assert_includes
@assertion_count = 2

Expand Down

0 comments on commit cb593b5

Please sign in to comment.