-
-
Notifications
You must be signed in to change notification settings - Fork 835
feat: add missing tests to ndarray/base/every-by
#7285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
headlessNode
wants to merge
6
commits into
stdlib-js:develop
Choose a base branch
from
headlessNode:test-every-by
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7449988
feat: add tests
headlessNode 1ddae2f
refactor: apply suggestions from code review
headlessNode 9c78425
fix: description
headlessNode 995a605
Merge branch 'test-every-by' of https://github.com/headlessNode/stdli…
headlessNode f1ca71a
fix: import
headlessNode 175b530
fix: cleanup
headlessNode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
lib/node_modules/@stdlib/ndarray/base/every-by/test/test.1d.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var tape = require( 'tape' ); | ||
var ones = require( '@stdlib/array/ones' ); | ||
var zeros = require( '@stdlib/array/zeros' ); | ||
var real = require( '@stdlib/complex/float64/real' ); | ||
var imag = require( '@stdlib/complex/float64/imag' ); | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var ndarray = require( '@stdlib/ndarray/ctor' ); | ||
var everyBy = require( './../lib' ); | ||
|
||
|
||
// TESTS // | ||
|
||
tape( 'main export is a function', function test( t ) { | ||
t.ok( true, __filename ); | ||
t.strictEqual( typeof everyBy, 'function', 'main export is a function'); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the function tests whether every element in a 1-dimensional ndarray passes a test implemented by a predicate function', function test( t ) { | ||
var actual; | ||
var x; | ||
|
||
x = ndarray( 'float64', zeros( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); | ||
|
||
actual = everyBy( [ x ], clbk ); | ||
t.strictEqual( actual, false, 'returns expected value' ); | ||
|
||
x = ndarray( 'float64', ones( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); | ||
|
||
actual = everyBy( [ x ], clbk ); | ||
t.strictEqual( actual, true, 'returns expected value' ); | ||
|
||
t.end(); | ||
|
||
function clbk( v ) { | ||
return v !== 0; | ||
} | ||
}); | ||
|
||
tape( 'the function tests whether every element in a 1-dimensional ndarray passes a test implemented by a predicate function (accessors)', function test( t ) { | ||
var actual; | ||
var xbuf; | ||
var x; | ||
|
||
xbuf = zeros( 6*2, 'float64' ); | ||
x = ndarray( 'complex128', new Complex128Array( xbuf ), [ 4 ], [ 1 ], 1, 'row-major' ); | ||
|
||
actual = everyBy( [ x ], clbk ); | ||
t.strictEqual( actual, false, 'returns expected value' ); | ||
|
||
xbuf = ones( 6*2, 'float64' ); | ||
x = ndarray( 'complex128', new Complex128Array( xbuf ), [ 4 ], [ 1 ], 1, 'row-major' ); | ||
|
||
actual = everyBy( [ x ], clbk ); | ||
t.strictEqual( actual, true, 'returns expected value' ); | ||
|
||
t.end(); | ||
|
||
function clbk( v ) { | ||
return ( real( v ) !== 0.0 && imag( v ) !== 0.0 ); | ||
} | ||
}); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding four tests here, all of which should be testing that the function supports providing a callback execution context. I say four tests, as you want one for indexed arrays and another for accessor arrays in both row and column-major orders.
In those tests, you should cache provided callback arguments and test that provided arguments match expectation. In particular, that the sequence of values is correct, that the sequence of indices is correct, and that the array is provided on each call.
For reference, see also
stdlib/lib/node_modules/@stdlib/stats/max-by/test/test.main.js
Line 974 in 38c6617