Skip to content

Commit 9e2d30f

Browse files
authored
Added stresstest
1 parent 2719e39 commit 9e2d30f

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

app/engine/utils/Series.test.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
'use strict'
2-
/*
3-
Open Rowing Monitor, https://github.com/JaapvanEkris/openrowingmonitor
4-
*/
52
/**
6-
* As this object is fundamental for most other utility objects, we must test its behaviour quite thoroughly
3+
* @copyright [OpenRowingMonitor]{@link https://github.com/JaapvanEkris/openrowingmonitor}
4+
*
5+
* @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.
78
*/
89
import { test } from 'uvu'
910
import * as assert from 'uvu/assert'
1011

1112
import { createSeries } from './Series.js'
1213

14+
/**
15+
* @description Test behaviour for no datapoints
16+
*/
1317
test('Series behaviour with an empty series', () => {
1418
const dataSeries = createSeries(3)
1519
testLength(dataSeries, 0)
@@ -26,6 +30,9 @@ test('Series behaviour with an empty series', () => {
2630
testMaximum(dataSeries, 0)
2731
})
2832

33+
/**
34+
* @description Test behaviour for a single datapoint
35+
*/
2936
test('Series behaviour with a single pushed value. Series = [9]', () => {
3037
const dataSeries = createSeries(3)
3138
dataSeries.push(9)
@@ -43,6 +50,9 @@ test('Series behaviour with a single pushed value. Series = [9]', () => {
4350
testMaximum(dataSeries, 9)
4451
})
4552

53+
/**
54+
* @description Test behaviour for two datapoints
55+
*/
4656
test('Series behaviour with a second pushed value. Series = [9, 3]', () => {
4757
const dataSeries = createSeries(3)
4858
dataSeries.push(9)
@@ -61,6 +71,9 @@ test('Series behaviour with a second pushed value. Series = [9, 3]', () => {
6171
testMaximum(dataSeries, 9)
6272
})
6373

74+
/**
75+
* @description Test behaviour for three datapoints
76+
*/
6477
test('Series behaviour with a third pushed value. Series = [9, 3, 6]', () => {
6578
const dataSeries = createSeries(3)
6679
dataSeries.push(9)
@@ -80,6 +93,9 @@ test('Series behaviour with a third pushed value. Series = [9, 3, 6]', () => {
8093
testMaximum(dataSeries, 9)
8194
})
8295

96+
/**
97+
* @description Test behaviour for four datapoints
98+
*/
8399
test('Series behaviour with a fourth pushed value. Series = [3, 6, 12]', () => {
84100
const dataSeries = createSeries(3)
85101
dataSeries.push(9)
@@ -100,6 +116,9 @@ test('Series behaviour with a fourth pushed value. Series = [3, 6, 12]', () => {
100116
testMaximum(dataSeries, 12)
101117
})
102118

119+
/**
120+
* @description Test behaviour for five datapoints
121+
*/
103122
test('Series behaviour with a fifth pushed value. Series = [6, 12, -3]', () => {
104123
const dataSeries = createSeries(3)
105124
dataSeries.push(9)
@@ -121,6 +140,9 @@ test('Series behaviour with a fifth pushed value. Series = [6, 12, -3]', () => {
121140
testMaximum(dataSeries, 12)
122141
})
123142

143+
/**
144+
* @description Test behaviour for recalculations of the min/max values
145+
*/
124146
test('Series behaviour pushing out the min and max value and forcing a recalculate of min/max via the array.', () => {
125147
const dataSeries = createSeries(3)
126148
dataSeries.push(9)
@@ -136,6 +158,9 @@ test('Series behaviour pushing out the min and max value and forcing a recalcula
136158
testMaximum(dataSeries, 6)
137159
})
138160

161+
/**
162+
* @description Test behaviour for recalculations of the min/max values
163+
*/
139164
test('Series behaviour pushing out the min and max value, replacing them just in time.', () => {
140165
const dataSeries = createSeries(3)
141166
dataSeries.push(9)
@@ -151,6 +176,9 @@ test('Series behaviour pushing out the min and max value, replacing them just in
151176
testMaximum(dataSeries, 12)
152177
})
153178

179+
/**
180+
* @description Test behaviour after a reset()
181+
*/
154182
test('Series behaviour with a five pushed values followed by a reset, Series = []', () => {
155183
const dataSeries = createSeries(3)
156184
dataSeries.push(9)
@@ -171,6 +199,43 @@ test('Series behaviour with a five pushed values followed by a reset, Series = [
171199
testMedian(dataSeries, 0)
172200
})
173201

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+
174239
function testLength (series, expectedValue) {
175240
assert.ok(series.length() === expectedValue, `Expected length should be ${expectedValue}, encountered ${series.length()}`)
176241
}

0 commit comments

Comments
 (0)