FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
luaplot/maths_test.lua at master · thewizardplusplus/luaplot · GitHub
thewizardplusplus
/
luaplot
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
luaplot
/
maths_test.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
134 lines (113 loc) · 2.84 KB
Breadcrumbs
luaplot
/
maths_test.lua
Copy path
File metadata and controls
134 lines (113 loc) · 2.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
local
luaunit
=
require
(
"
luaunit
"
)
local
maths
=
require
(
"
luaplot.maths
"
)
local
checks
=
require
(
"
luatypechecks.checks
"
)
--
luacheck: globals TestMaths
TestMaths
=
{}
function
TestMaths
.
test_clamp_middle
()
local
result
=
maths
.
clamp
(
32
,
23
,
42
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
32
)
end
function
TestMaths
.
test_clamp_minimum
()
local
result
=
maths
.
clamp
(
23
,
23
,
42
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
23
)
end
function
TestMaths
.
test_clamp_before_minimum
()
local
result
=
maths
.
clamp
(
22
,
23
,
42
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
23
)
end
function
TestMaths
.
test_clamp_maximum
()
local
result
=
maths
.
clamp
(
42
,
23
,
42
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
42
)
end
function
TestMaths
.
test_clamp_after_maximum
()
local
result
=
maths
.
clamp
(
43
,
23
,
42
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
42
)
end
function
TestMaths
.
test_lerp_middle
()
local
result
=
maths
.
lerp
(
23
,
42
,
0.2
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
26.8
)
end
function
TestMaths
.
test_lerp_minimum
()
local
result
=
maths
.
lerp
(
23
,
42
,
0
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
23
)
end
function
TestMaths
.
test_lerp_maximum
()
local
result
=
maths
.
lerp
(
23
,
42
,
1
)
luaunit
.
assert_is_number
(
result
)
luaunit
.
assert_equals
(
result
,
42
)
end
function
TestMaths
.
test_random_in_range
()
math.randomseed
(
1
)
local
results
=
{}
for
_
=
1
,
10
do
local
result
=
maths
.
random_in_range
(
23
,
42
)
table.insert
(
results
,
result
)
end
local
wanted_results
if
_VERSION
==
"
Lua 5.5
"
or
_VERSION
==
"
Lua 5.4
"
then
wanted_results
=
{
38.496168
,
41.744973
,
24.507284
,
32.474321
,
34.244394
,
38.845409
,
25.936408
,
28.019722
,
27.905971
,
37.831421
,
}
elseif
_VERSION
==
"
Lua 5.3
"
or
_VERSION
==
"
Lua 5.2
"
then
wanted_results
=
{
30.493276
,
37.878885
,
38.170361
,
40.321300
,
26.753476
,
29.369232
,
37.596362
,
28.277720
,
33.525429
,
32.070544
,
}
elseif
_VERSION
==
"
Lua 5.1
"
then
if
checks
.
is_table
(
jit
)
then
--
check for LuaJIT
wanted_results
=
{
29.152401
,
23.258655
,
40.341720
,
28.675371
,
25.056512
,
25.001620
,
27.543950
,
38.933066
,
41.363617
,
29.867614
,
}
else
wanted_results
=
{
38.963567
,
30.493276
,
37.878885
,
38.170361
,
40.321300
,
26.753476
,
29.369232
,
37.596362
,
28.277720
,
33.525429
,
}
end
end
luaunit
.
assert_equals
(
#
results
,
#
wanted_results
)
for
index
,
result
in
ipairs
(
results
)
do
luaunit
.
assert_almost_equals
(
result
,
wanted_results
[
index
],
1e-6
)
end
end
Back
|
FazBrowse Home
|
New Git URL