summaryrefslogtreecommitdiff
path: root/Data/Libraries/luaunit/test/check_lua_calc_error.lua
blob: 448be7208ffdc125efa01a48523af3469130a72c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 )