Skip to content

Commit

Permalink
Fixed float tolerance in tests when MRB_USE_FLOAT is set
Browse files Browse the repository at this point in the history
  • Loading branch information
dabroz committed Nov 24, 2016
1 parent 0c924b9 commit a8b8abb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mrbgems/mruby-test/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose)
mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN));
mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT));

#ifdef MRB_USE_FLOAT
mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-6));
#else
mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-12));
#endif

if (verbose) {
mrb_gv_set(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"), mrb_true_value());
}
Expand Down
2 changes: 1 addition & 1 deletion test/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def report()
##
# Performs fuzzy check for equality on methods returning floats
def check_float(a, b)
tolerance = 1e-12
tolerance = Mrbtest::FLOAT_TOLERANCE
a = a.to_f
b = b.to_f
if a.finite? and b.finite?
Expand Down

0 comments on commit a8b8abb

Please sign in to comment.