diff options
author | chai <chaifix@163.com> | 2021-10-20 13:36:36 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-20 13:36:36 +0800 |
commit | dde719dd575090b36aaa3ad85bb3cabf33f36c5a (patch) | |
tree | 3e0a8e70f716dbfee2f644f5202da7ee74b3c6b7 /Resources/Libraries/luaunit/test/check_lua_calc_error.lua | |
parent | 943411c9006345b07557e76ff360c388ee8366c1 (diff) |
+luaunit test
Diffstat (limited to 'Resources/Libraries/luaunit/test/check_lua_calc_error.lua')
-rw-r--r-- | Resources/Libraries/luaunit/test/check_lua_calc_error.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Resources/Libraries/luaunit/test/check_lua_calc_error.lua b/Resources/Libraries/luaunit/test/check_lua_calc_error.lua new file mode 100644 index 0000000..448be72 --- /dev/null +++ b/Resources/Libraries/luaunit/test/check_lua_calc_error.lua @@ -0,0 +1,23 @@ + +local lu = require('luaunit') + +print( lu.EPS ) + +local pi_div_6_deg_expected, pi_div_6_deg_calculated, pi_div_3_deg_expected, pi_div_3_deg_calculated + +pi_div_6_deg_calculated = math.deg(math.pi/6) +pi_div_6_deg_expected = 30 + +pi_div_3_deg_calculated = math.deg(math.pi/3) +pi_div_3_deg_expected = 60 + +print( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / lu.EPS ) -- prints: 16 +print( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / lu.EPS ) -- prints: 32 + +-- Better use relative error: +print( ( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / pi_div_6_deg_expected) / lu.EPS ) -- prints: 0.53333 +print( ( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / pi_div_3_deg_expected) / lu.EPS ) -- prints: 0.53333 + +-- relative error is constant. Assertion can take the form of: +lu.assertAlmostEquals( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / pi_div_6_deg_expected, 0, lu.EPS ) +lu.assertAlmostEquals( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / pi_div_3_deg_expected, 0, lu.EPS )
\ No newline at end of file |