-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_math.t
73 lines (64 loc) · 1.67 KB
/
test_math.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
import "terratest/terratest"
local math = require('mathfuns')
local funs_single_var = {
"sin",
"cos",
"tan",
"asin",
"acos",
"atan",
"sinh",
"cosh",
"tanh",
"asinh",
"acosh",
"atanh",
"exp",
"exp2",
"log",
"log10",
"sqrt",
"cbrt",
"erf",
"erfc",
"gamma",
"loggamma",
"abs"
}
testenv "All single variable math functions" do
--test correctness of output type
for k,f in ipairs(funs_single_var) do
local mathfun = math[f]
testset(f) "fun " do
terracode
var xfloat = mathfun([float](0))
var xdouble = mathfun([double](0))
end
test [xfloat.type == float]
test [xdouble.type == double]
end
end
end
testenv "Correctness of selected math functions" do
--test if result is correct
testset "sqrt" do
test math.isapprox(math.sqrt([float](4)), 2.0f, 1e-7f)
test math.isapprox(math.sqrt([double](4)), 2.0, 1e-15)
end
testset "log" do
test math.isapprox(math.log([float](1)), 0, 1e-7f)
test math.isapprox(math.log([double](1)), 0, 1e-15)
end
testset "sin" do
test math.isapprox(math.sin([float](math.pi)), 0, 1e-7f)
test math.isapprox(math.sin([double](math.pi)), 0, 1e-15)
end
testset "cos" do
test math.isapprox(math.cos([float](math.pi)), -1, 1e-7f)
test math.isapprox(math.cos([double](math.pi)), -1, 1e-15)
end
end