You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @file Tests of the Series object. As this object is fundamental for most other utility objects, we must test its behaviour quite thoroughly
6
+
* Please note: this file contains commented out stress tests of the length(), sum(), average() functions, to detect any issues with numerical stability
7
+
* As these tests tend to run in the dozens of minutes, we do not run them systematically, but they should be run when the series object is changed.
7
8
*/
8
9
import{test}from'uvu'
9
10
import*asassertfrom'uvu/assert'
10
11
11
12
import{createSeries}from'./Series.js'
12
13
14
+
/**
15
+
* @description Test behaviour for no datapoints
16
+
*/
13
17
test('Series behaviour with an empty series',()=>{
14
18
constdataSeries=createSeries(3)
15
19
testLength(dataSeries,0)
@@ -26,6 +30,9 @@ test('Series behaviour with an empty series', () => {
26
30
testMaximum(dataSeries,0)
27
31
})
28
32
33
+
/**
34
+
* @description Test behaviour for a single datapoint
35
+
*/
29
36
test('Series behaviour with a single pushed value. Series = [9]',()=>{
30
37
constdataSeries=createSeries(3)
31
38
dataSeries.push(9)
@@ -43,6 +50,9 @@ test('Series behaviour with a single pushed value. Series = [9]', () => {
43
50
testMaximum(dataSeries,9)
44
51
})
45
52
53
+
/**
54
+
* @description Test behaviour for two datapoints
55
+
*/
46
56
test('Series behaviour with a second pushed value. Series = [9, 3]',()=>{
47
57
constdataSeries=createSeries(3)
48
58
dataSeries.push(9)
@@ -61,6 +71,9 @@ test('Series behaviour with a second pushed value. Series = [9, 3]', () => {
61
71
testMaximum(dataSeries,9)
62
72
})
63
73
74
+
/**
75
+
* @description Test behaviour for three datapoints
76
+
*/
64
77
test('Series behaviour with a third pushed value. Series = [9, 3, 6]',()=>{
65
78
constdataSeries=createSeries(3)
66
79
dataSeries.push(9)
@@ -80,6 +93,9 @@ test('Series behaviour with a third pushed value. Series = [9, 3, 6]', () => {
80
93
testMaximum(dataSeries,9)
81
94
})
82
95
96
+
/**
97
+
* @description Test behaviour for four datapoints
98
+
*/
83
99
test('Series behaviour with a fourth pushed value. Series = [3, 6, 12]',()=>{
84
100
constdataSeries=createSeries(3)
85
101
dataSeries.push(9)
@@ -100,6 +116,9 @@ test('Series behaviour with a fourth pushed value. Series = [3, 6, 12]', () => {
100
116
testMaximum(dataSeries,12)
101
117
})
102
118
119
+
/**
120
+
* @description Test behaviour for five datapoints
121
+
*/
103
122
test('Series behaviour with a fifth pushed value. Series = [6, 12, -3]',()=>{
104
123
constdataSeries=createSeries(3)
105
124
dataSeries.push(9)
@@ -121,6 +140,9 @@ test('Series behaviour with a fifth pushed value. Series = [6, 12, -3]', () => {
121
140
testMaximum(dataSeries,12)
122
141
})
123
142
143
+
/**
144
+
* @description Test behaviour for recalculations of the min/max values
145
+
*/
124
146
test('Series behaviour pushing out the min and max value and forcing a recalculate of min/max via the array.',()=>{
125
147
constdataSeries=createSeries(3)
126
148
dataSeries.push(9)
@@ -136,6 +158,9 @@ test('Series behaviour pushing out the min and max value and forcing a recalcula
136
158
testMaximum(dataSeries,6)
137
159
})
138
160
161
+
/**
162
+
* @description Test behaviour for recalculations of the min/max values
163
+
*/
139
164
test('Series behaviour pushing out the min and max value, replacing them just in time.',()=>{
140
165
constdataSeries=createSeries(3)
141
166
dataSeries.push(9)
@@ -151,6 +176,9 @@ test('Series behaviour pushing out the min and max value, replacing them just in
151
176
testMaximum(dataSeries,12)
152
177
})
153
178
179
+
/**
180
+
* @description Test behaviour after a reset()
181
+
*/
154
182
test('Series behaviour with a five pushed values followed by a reset, Series = []',()=>{
155
183
constdataSeries=createSeries(3)
156
184
dataSeries.push(9)
@@ -171,6 +199,43 @@ test('Series behaviour with a five pushed values followed by a reset, Series = [
171
199
testMedian(dataSeries,0)
172
200
})
173
201
202
+
/* These stress tests test the reliability of the sum(), average() and length() function after a huge number of updates
203
+
// This specific test takes a long time (over 10 minutes), so only run them manually when changing the series module
204
+
// Javascript maximum array length is 4294967295, as heap memory is limited, we stay with 2^25 datapoints
205
+
test('Stress test of the series object, 33.554.432 (2^25) datapoints', () => {
206
+
const dataSeries = createSeries()
207
+
let j = 0
208
+
let randomvalue
209
+
while (j < 16777216) {
210
+
randomvalue = Math.random()
211
+
dataSeries.push(randomvalue)
212
+
dataSeries.push(1 - randomvalue)
213
+
j++
214
+
}
215
+
testLength(dataSeries, 33554432)
216
+
testSum(dataSeries, 16777216)
217
+
testAverage(dataSeries, 0.5)
218
+
testMedian(dataSeries, 0.5)
219
+
})
220
+
221
+
// Javascript maximum array length is 4294967295, as heap memory is limited, we stay with 2^25 datapoints
222
+
// This test takes several hours (!) due to the many large array shifts, so only run them manually when changing the series module
223
+
test('Stress test of the series object, 67.108.864 datapoints, with a maxLength of 33.554.432 (2^25)', () => {
224
+
const dataSeries = createSeries(33554432)
225
+
let j = 0
226
+
let randomvalue
227
+
while (j < 33554432) {
228
+
randomvalue = Math.random()
229
+
dataSeries.push(randomvalue)
230
+
dataSeries.push(1 - randomvalue)
231
+
j++
232
+
}
233
+
testLength(dataSeries, 33554432)
234
+
testSum(dataSeries, 16777216)
235
+
testAverage(dataSeries, 0.5)
236
+
testMedian(dataSeries, 0.5)
237
+
}) */
238
+
174
239
functiontestLength(series,expectedValue){
175
240
assert.ok(series.length()===expectedValue,`Expected length should be ${expectedValue}, encountered ${series.length()}`)
0 commit comments