From d8c8893e94fb10724513cf2c59d142aa5238ea2c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 15 Jun 2013 02:10:05 +0800 Subject: Implement assert_float and add block mode to assert_equal and assert_not_equal --- test/assert.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'test/assert.rb') diff --git a/test/assert.rb b/test/assert.rb index 6d727e889..98057331b 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -62,7 +62,7 @@ def assert(str = 'Assertion failed', iso = '') $asserts.push(assertion_string('Error: ', str, iso, e)) $kill_test += 1 t_print('X') - end + end ensure $mrbtest_assert = nil end @@ -99,13 +99,25 @@ def assert_false(ret, msg = nil, diff = nil) !ret end -def assert_equal(exp, act, msg = nil) +def assert_equal(arg1, arg2 = nil, arg3 = nil) + if block_given? + exp, act, msg = yield, arg1, arg2 + else + exp, act, msg = arg1, arg2, arg3 + end + msg = "Expected to be equal" unless msg diff = assertion_diff(exp, act) assert_true(exp == act, msg, diff) end -def assert_not_equal(exp, act, msg = nil) +def assert_not_equal(arg1, arg2 = nil, arg3 = nil) + if block_given? + exp, act, msg = yield, arg1, arg2 + else + exp, act, msg = arg1, arg2, arg3 + end + msg = "Expected to be not equal" unless msg diff = assertion_diff(exp, act) assert_false(exp == act, msg, diff) @@ -169,6 +181,14 @@ def assert_kind_of(cls, obj, msg = nil) assert_true(obj.kind_of?(cls), msg, diff) end +## +# Fails unless +exp+ is equal to +act+ in terms of a Float +def assert_float(exp, act, msg = nil) + msg = "Float #{exp} expected to be equal to float #{act}" unless msg + diff = assertion_diff(exp, act) + assert_true check_float(exp, act), msg, diff +end + ## # Report the test result and print all assertions # which were reported broken. -- cgit v1.2.3