FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
luaplot/oscillogram_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
/
oscillogram_test.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
125 lines (95 loc) · 3.31 KB
Breadcrumbs
luaplot
/
oscillogram_test.lua
Copy path
File metadata and controls
125 lines (95 loc) · 3.31 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
local
luaunit
=
require
(
"
luaunit
"
)
local
checks
=
require
(
"
luatypechecks.checks
"
)
local
Oscillogram
=
require
(
"
luaplot.oscillogram
"
)
--
luacheck: globals TestOscillogram
TestOscillogram
=
{}
function
TestOscillogram
.
test_new_full
()
local
plot
=
Oscillogram
:
new
(
"
random
"
,
5
,
32
,
23
,
42
)
luaunit
.
assert_is_table
(
plot
)
luaunit
.
assert_true
(
checks
.
is_instance
(
plot
,
Oscillogram
))
luaunit
.
assert_is_string
(
plot
.
_kind
)
luaunit
.
assert_equals
(
plot
.
_kind
,
"
random
"
)
luaunit
.
assert_is_table
(
plot
.
_points
)
luaunit
.
assert_equals
(
plot
.
_points
, {
32
,
32
,
32
,
32
,
32
})
luaunit
.
assert_is_number
(
plot
.
_default
)
luaunit
.
assert_equals
(
plot
.
_default
,
32
)
luaunit
.
assert_is_number
(
plot
.
_minimum
)
luaunit
.
assert_equals
(
plot
.
_minimum
,
23
)
luaunit
.
assert_is_number
(
plot
.
_maximum
)
luaunit
.
assert_equals
(
plot
.
_maximum
,
42
)
end
function
TestOscillogram
.
test_new_partial
()
local
plot
=
Oscillogram
:
new
(
"
random
"
,
5
)
luaunit
.
assert_is_table
(
plot
)
luaunit
.
assert_true
(
checks
.
is_instance
(
plot
,
Oscillogram
))
luaunit
.
assert_is_string
(
plot
.
_kind
)
luaunit
.
assert_equals
(
plot
.
_kind
,
"
random
"
)
luaunit
.
assert_is_table
(
plot
.
_points
)
luaunit
.
assert_equals
(
plot
.
_points
, {
0
,
0
,
0
,
0
,
0
})
luaunit
.
assert_is_number
(
plot
.
_default
)
luaunit
.
assert_equals
(
plot
.
_default
,
0
)
luaunit
.
assert_is_number
(
plot
.
_minimum
)
luaunit
.
assert_equals
(
plot
.
_minimum
,
0
)
luaunit
.
assert_is_number
(
plot
.
_maximum
)
luaunit
.
assert_equals
(
plot
.
_maximum
,
1
)
end
function
TestOscillogram
.
test_tostring
()
local
plot
=
Oscillogram
:
new
(
"
random
"
,
5
,
32
,
23
,
42
)
local
text
=
tostring
(
plot
)
luaunit
.
assert_is_string
(
text
)
luaunit
.
assert_equals
(
text
,
"
{
"
..
"
__name =
\"
Oscillogram
\"
,
"
..
"
default = 32,
"
..
"
kind =
\"
random
\"
,
"
..
"
maximum = 42,
"
..
"
minimum = 23,
"
..
"
points = { 32, 32, 32, 32, 32 }
"
..
"
}
"
)
end
function
TestOscillogram
.
test_update_custom
()
local
plot
=
Oscillogram
:
new
(
"
custom
"
,
0
,
0.5
)
for
i
=
1
,
5
do
plot
:
push
(
i
/
10
)
end
local
first_point
=
plot
:
update
(
0.2
)
luaunit
.
assert_is_table
(
plot
.
_points
)
luaunit
.
assert_equals
(
plot
.
_points
, {
0.2
,
0.3
,
0.4
,
0.5
,
0.2
})
luaunit
.
assert_is_number
(
first_point
)
luaunit
.
assert_equals
(
first_point
,
0.1
)
end
function
TestOscillogram
.
test_update_linear
()
local
plot
=
Oscillogram
:
new
(
"
linear
"
,
0
,
0.5
)
for
i
=
1
,
5
do
plot
:
push
(
i
/
10
)
end
local
first_point
=
plot
:
update
(
0.2
)
luaunit
.
assert_is_table
(
plot
.
_points
)
luaunit
.
assert_equals
(
plot
.
_points
, {
0.2
,
0.3
,
0.4
,
0.5
,
0.7
})
luaunit
.
assert_is_number
(
first_point
)
luaunit
.
assert_equals
(
first_point
,
0.1
)
end
function
TestOscillogram
.
test_update_random
()
math.randomseed
(
1
)
local
plot
=
Oscillogram
:
new
(
"
random
"
,
0
,
0.5
)
for
i
=
1
,
5
do
plot
:
push
(
i
/
10
)
end
local
first_point
=
plot
:
update
(
0.2
)
local
last_point
if
_VERSION
==
"
Lua 5.5
"
or
_VERSION
==
"
Lua 5.4
"
then
last_point
=
0.626235
elseif
_VERSION
==
"
Lua 5.3
"
or
_VERSION
==
"
Lua 5.2
"
then
last_point
=
0.457753
elseif
_VERSION
==
"
Lua 5.1
"
then
if
checks
.
is_table
(
jit
)
then
--
check for LuaJIT
last_point
=
0.429524
else
last_point
=
0.636075
end
end
luaunit
.
assert_is_table
(
plot
.
_points
)
luaunit
.
assert_equals
(
#
plot
.
_points
,
5
)
luaunit
.
assert_almost_equals
(
plot
.
_points
[
5
],
last_point
,
1e-6
)
luaunit
.
assert_is_number
(
first_point
)
luaunit
.
assert_equals
(
first_point
,
0.1
)
end
Back
|
FazBrowse Home
|
New Git URL