Skip to content

Commit 33e1412

Browse files
committed
edit
1 parent dedd615 commit 33e1412

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
var randu = require( '@stdlib/random/base/randu' );
2222
var incrnanmmin = require( './../lib' );
23+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2324

2425
var accumulator;
2526
var m;

lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -105,58 +105,51 @@ tape( 'if data has yet to be provided, the accumulator function returns `null`',
105105
t.end();
106106
});
107107

108-
tape( 'the accumulator function correctly handles signed zeros while ignoring NaNs', function test( t ) {
108+
tape( 'the accumulator function computes a moving minimum incrementally, ignoring NaN values', function test( t ) {
109109
var expected;
110+
var actual;
110111
var data;
111112
var acc;
112-
var v;
113+
var N;
113114
var i;
114115

115-
acc = incrnanmmin( 3 );
116+
data = [ 2.0, NaN, 3.0, 2.0, NaN, 4.0, 3.0, NaN, 4.0, 2.0, 2.0, NaN, 1.0, 4.0 ];
117+
N = data.length;
116118

117-
data = [
118-
0.0, // 0
119-
-0.0, // 0, -0
120-
NaN, // ignored
121-
0.0, // 0, -0, 0
122-
NaN, // ignored
123-
-0.0, // -0, 0, -0
124-
0.0, // 0, -0, 0
125-
NaN, // ignored
126-
-0.0, // -0, 0, -0
127-
0.0, // 0, -0, 0
128-
-0.0, // -0, 0, -0
129-
-0.0, // -0, -0, -0
130-
0.0 // -0, -0, 0
131-
];
119+
acc = incrnanmmin( 3 ); // Moving window of size 3
132120

121+
actual = [];
122+
for ( i = 0; i < N; i++ ) {
123+
actual.push( acc( data[ i ] ) );
124+
}
125+
126+
// Expected minimum values, ignoring NaN
133127
expected = [
134-
0.0,
135-
-0.0,
136-
-0.0, // NaN ignored
137-
-0.0,
138-
-0.0, // NaN ignored
139-
-0.0,
140-
-0.0,
141-
-0.0, // NaN ignored
142-
-0.0,
143-
-0.0,
144-
-0.0,
145-
-0.0,
146-
-0.0
128+
2.0, // [ 2.0 ]
129+
2.0, // [ 2.0 ] (NaN ignored)
130+
2.0, // [ 2.0, 3.0 ]
131+
2.0, // [ 2.0, 3.0, 2.0 ]
132+
2.0, // [ 2.0, 3.0, 2.0 ] (NaN ignored)
133+
2.0, // [ 3.0, 2.0, 4.0 ] (window moves)
134+
2.0, // [ 2.0, 4.0, 3.0 ]
135+
2.0, // [ 2.0, 4.0, 3.0 ] (NaN ignored)
136+
3.0, // [ 4.0, 3.0, 4.0 ]
137+
2.0, // [ 3.0, 4.0, 2.0 ]
138+
2.0, // [ 4.0, 2.0, 2.0 ]
139+
2.0, // [ 4.0, 2.0, 2.0 ] (NaN ignored)
140+
1.0, // [ 2.0, 2.0, 1.0 ]
141+
1.0 // [ 2.0, 1.0, 4.0 ]
147142
];
148143

149-
for ( i = 0; i < data.length; i++ ) {
150-
v = acc( data[ i ] );
151-
if ( isnan( data[i] ) ) {
152-
continue;
153-
}
154-
if ( isNegativeZero( expected[ i ] ) ) {
155-
t.equal( isNegativeZero( v ), true, 'returns expected value for window ' + i );
144+
// Check the computed values against the expected values
145+
for ( i = 0; i < N; i++ ) {
146+
if ( isNaN( expected[i] ) ) {
147+
t.equal( isNaN(actual[i]), true, 'returns NaN at index ' + i );
156148
} else {
157-
t.equal( isPositiveZero( v ), true, 'returns expected value for window ' + i );
149+
t.equal( actual[i], expected[i], 'returns expected value at index ' + i );
158150
}
159151
}
152+
160153
t.end();
161154
});
162155

0 commit comments

Comments
 (0)