Skip to content

Commit 89ab24a

Browse files
committed
test: add ctx cases
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 175b530 commit 89ab24a

File tree

2 files changed

+398
-0
lines changed

2 files changed

+398
-0
lines changed

lib/node_modules/@stdlib/ndarray/base/every-by/test/test.1d.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,121 @@ tape( 'the function tests whether every element in a 1-dimensional ndarray passe
8282
return ( real( v ) !== 0.0 && imag( v ) !== 0.0 );
8383
}
8484
});
85+
86+
tape( 'the function supports specifying the callback execution context', function test( t ) {
87+
var expected;
88+
var indices;
89+
var values;
90+
var arrays;
91+
var actual;
92+
var ctx;
93+
var x;
94+
95+
x = new ndarray( 'float64', ones( 8, 'float64'), [ 4 ], [ 2 ], 0, 'row-major' );
96+
97+
indices = [];
98+
values = [];
99+
arrays = [];
100+
101+
ctx = {
102+
'count': 0
103+
};
104+
actual = everyBy( [ x ], clbk, ctx );
105+
106+
t.strictEqual( actual, true, 'returns expected value' );
107+
t.strictEqual( ctx.count, 4, 'returns expected value' );
108+
109+
expected = [
110+
1.0,
111+
1.0,
112+
1.0,
113+
1.0
114+
];
115+
t.deepEqual( values, expected, 'returns expected value' );
116+
117+
expected = [
118+
[ 0 ],
119+
[ 1 ],
120+
[ 2 ],
121+
[ 3 ]
122+
];
123+
t.deepEqual( indices, expected, 'returns expected value' );
124+
125+
expected = [
126+
x,
127+
x,
128+
x,
129+
x
130+
];
131+
t.deepEqual( arrays, expected, 'returns expected value' );
132+
133+
t.end();
134+
135+
function clbk( v, idx, arr ) {
136+
this.count += 1; // eslint-disable-line no-invalid-this
137+
values.push( v );
138+
indices.push( idx );
139+
arrays.push( arr );
140+
return v !== 0.0;
141+
}
142+
});
143+
144+
tape( 'the function supports specifying the callback execution context (accessors)', function test( t ) {
145+
var expected;
146+
var indices;
147+
var values;
148+
var arrays;
149+
var actual;
150+
var xbuf;
151+
var ctx;
152+
var x;
153+
154+
xbuf = ones( 6*2, 'float64' );
155+
x = ndarray( 'complex128', new Complex128Array( xbuf ), [ 4 ], [ 1 ], 1, 'row-major' );
156+
157+
indices = [];
158+
values = [];
159+
arrays = [];
160+
161+
ctx = {
162+
'count': 0
163+
};
164+
actual = everyBy( [ x ], clbk, ctx );
165+
166+
t.strictEqual( actual, true, 'returns expected value' );
167+
t.strictEqual( ctx.count, 4, 'returns expected value' );
168+
169+
expected = [
170+
[ 1.0, 1.0 ],
171+
[ 1.0, 1.0 ],
172+
[ 1.0, 1.0 ],
173+
[ 1.0, 1.0 ]
174+
];
175+
t.deepEqual( values, expected, 'returns expected value' );
176+
177+
expected = [
178+
[ 0 ],
179+
[ 1 ],
180+
[ 2 ],
181+
[ 3 ]
182+
];
183+
t.deepEqual( indices, expected, 'returns expected value' );
184+
185+
expected = [
186+
x,
187+
x,
188+
x,
189+
x
190+
];
191+
t.deepEqual( arrays, expected, 'returns expected value' );
192+
193+
t.end();
194+
195+
function clbk( v, idx, arr ) {
196+
this.count += 1; // eslint-disable-line no-invalid-this
197+
values.push( [ real( v ), imag( v ) ] );
198+
indices.push( idx );
199+
arrays.push( arr );
200+
return ( real( v ) !== 0.0 && imag( v ) !== 0.0 );
201+
}
202+
});

0 commit comments

Comments
 (0)