From 501f7f6027b99416b94f093bb30691c5ae43d7d0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 5 Jun 2012 09:09:50 +0900 Subject: stop introducing Math::TORELANCE --- test/assert.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/assert.rb') diff --git a/test/assert.rb b/test/assert.rb index 239730cb9..5cca59187 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -74,12 +74,12 @@ end # Performs fuzzy check for equality on methods returning floats # on the basis of the Math::TOLERANCE constant. def check_float(a, b) + tolerance = 1e-12 a = a.to_f b = b.to_f if a.finite? and b.finite? - (a-b).abs < Math::TOLERANCE + (a-b).abs < tolerance else true end end - -- cgit v1.2.3 From bddbf20785c322111441d9e9569cf8e85c7d8c3e Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 13 Jun 2012 09:41:24 +0900 Subject: Assert should handle all exceptions. --- test/assert.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/assert.rb') diff --git a/test/assert.rb b/test/assert.rb index 5cca59187..2fc11f149 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -32,7 +32,7 @@ def assert(str = 'Assertion failed', iso = '') $ok_test += 1 print('.') end - rescue => e + rescue Exception => e $asserts.push(['Error: ', str, iso, e]) $kill_test += 1 print('X') -- cgit v1.2.3 From 2ae84f7d8358628bd904993aef18edf27828d696 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 21 Jun 2012 16:00:04 +0800 Subject: Add execution time to tests --- test/assert.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/assert.rb') diff --git a/test/assert.rb b/test/assert.rb index 2fc11f149..9329638c9 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -2,6 +2,7 @@ $ok_test = 0 $ko_test = 0 $kill_test = 0 $asserts = [] +$test_start = Time.now if Object.const_defined?(:Time) ## # Print the assertion in a readable way @@ -68,6 +69,12 @@ def report() print('Crash: ') print($kill_test) print("\n") + + if Object.const_defined?(:Time) + print(' Time: ') + print(Time.now - $test_start) + print(" seconds\n") + end end ## @@ -83,3 +90,4 @@ def check_float(a, b) true end end + -- cgit v1.2.3 From 34cf05679c5ce9ee40be6bd4ccace0ec94fcebdf Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 01:12:09 +0900 Subject: add Math::TOLERANCE --- src/math.c | 28 +++++++++++++++++----------- test/assert.rb | 3 +-- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'test/assert.rb') diff --git a/src/math.c b/src/math.c index 519d4f37b..fe10848c3 100644 --- a/src/math.c +++ b/src/math.c @@ -634,18 +634,24 @@ mrb_init_math(mrb_state *mrb) struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); - #ifdef M_PI - mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); - #else - mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); - #endif - - #ifdef M_E - mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); - #else - mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0))); - #endif +#ifdef M_PI + mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); +#else + mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); +#endif +#ifdef M_E + mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); +#else + mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0))); +#endif + +#ifdef MRB_USE_FLOAT + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-6)); +#else + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-12)); +#endif + mrb_define_module_function(mrb, mrb_math, "sin", math_sin, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "cos", math_cos, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "tan", math_tan, ARGS_REQ(1)); diff --git a/test/assert.rb b/test/assert.rb index 9329638c9..89e820a00 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -81,7 +81,7 @@ end # Performs fuzzy check for equality on methods returning floats # on the basis of the Math::TOLERANCE constant. def check_float(a, b) - tolerance = 1e-12 + tolerance = Math::TOLERANCE a = a.to_f b = b.to_f if a.finite? and b.finite? @@ -90,4 +90,3 @@ def check_float(a, b) true end end - -- cgit v1.2.3