Commit d8c8893e authored by Daniel Bovensiepen's avatar Daniel Bovensiepen

Implement assert_float and add block mode to assert_equal and assert_not_equal

parent cbc9c24f
...@@ -62,7 +62,7 @@ def assert(str = 'Assertion failed', iso = '') ...@@ -62,7 +62,7 @@ def assert(str = 'Assertion failed', iso = '')
$asserts.push(assertion_string('Error: ', str, iso, e)) $asserts.push(assertion_string('Error: ', str, iso, e))
$kill_test += 1 $kill_test += 1
t_print('X') t_print('X')
end end
ensure ensure
$mrbtest_assert = nil $mrbtest_assert = nil
end end
...@@ -99,13 +99,25 @@ def assert_false(ret, msg = nil, diff = nil) ...@@ -99,13 +99,25 @@ def assert_false(ret, msg = nil, diff = nil)
!ret !ret
end 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 msg = "Expected to be equal" unless msg
diff = assertion_diff(exp, act) diff = assertion_diff(exp, act)
assert_true(exp == act, msg, diff) assert_true(exp == act, msg, diff)
end 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 msg = "Expected to be not equal" unless msg
diff = assertion_diff(exp, act) diff = assertion_diff(exp, act)
assert_false(exp == act, msg, diff) assert_false(exp == act, msg, diff)
...@@ -169,6 +181,14 @@ def assert_kind_of(cls, obj, msg = nil) ...@@ -169,6 +181,14 @@ def assert_kind_of(cls, obj, msg = nil)
assert_true(obj.kind_of?(cls), msg, diff) assert_true(obj.kind_of?(cls), msg, diff)
end 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 # Report the test result and print all assertions
# which were reported broken. # which were reported broken.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment