Skip to content
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

add-test-case-in-dnansumk-and-in-native #3056

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 62 additions & 57 deletions lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,91 +20,91 @@

// MODULES //

var tape = require( 'tape' );
var Float64Array = require( '@stdlib/array/float64' );
var dnanasum = require( './../lib/dnanasum.js' );
var tape = require('tape');
var Float64Array = require('@stdlib/array/float64');
var dnanasum = require('./../lib/dnanasum.js');


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof dnanasum, 'function', 'main export is a function' );
tape('main export is a function', function test(t) {
t.ok(true, __filename);
t.strictEqual(typeof dnanasum, 'function', 'main export is a function');
t.end();
});

tape( 'the function has an arity of 3', function test( t ) {
t.strictEqual( dnanasum.length, 3, 'returns expected value' );
tape('the function has an arity of 3', function test(t) {
t.strictEqual(dnanasum.length, 3, 'returns expected value');
t.end();
});

tape( 'the function calculates the sum of absolute values (ignoring NaN values)', function test( t ) {
tape('the function calculates the sum of absolute values (ignoring NaN values)', function test(t) {
var x;
var v;

x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, NaN, 3.0, 0.0, -3.0, 3.0, NaN ] ); // eslint-disable-line max-len
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 21.0, 'returns expected value' );
x = new Float64Array([1.0, -2.0, -4.0, 5.0, 0.0, NaN, 3.0, 0.0, -3.0, 3.0, NaN]); // eslint-disable-line max-len
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 21.0, 'returns expected value');

x = new Float64Array( [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0, NaN ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 15.0, 'returns expected value' );
x = new Float64Array([1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0, NaN]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 15.0, 'returns expected value');

x = new Float64Array( [ -4.0, NaN, -4.0 ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 8.0, 'returns expected value' );
x = new Float64Array([-4.0, NaN, -4.0]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 8.0, 'returns expected value');

x = new Float64Array( [ NaN, 4.0 ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 4.0, 'returns expected value' );
x = new Float64Array([NaN, 4.0]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 4.0, 'returns expected value');

x = new Float64Array( [ NaN, NaN ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 0.0, 'returns expected value' );
x = new Float64Array([NaN, NaN]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 0.0, 'returns expected value');

x = new Float64Array( [ NaN ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 0.0, 'returns expected value' );
x = new Float64Array([NaN]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 0.0, 'returns expected value');

x = new Float64Array( [ 4.0 ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 4.0, 'returns expected value' );
x = new Float64Array([4.0]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 4.0, 'returns expected value');

x = new Float64Array( [ 1.0, 1.0e100, 1.0, -1.0e100 ] );
v = dnanasum( x.length, x, 1 );
t.strictEqual( v, 2.0e100, 'returns expected value' );
x = new Float64Array([1.0, 1.0e100, 1.0, -1.0e100]);
v = dnanasum(x.length, x, 1);
t.strictEqual(v, 2.0e100, 'returns expected value');

t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test( t ) {
tape('if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test(t) {
var x;
var v;

x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
x = new Float64Array([1.0, -2.0, -4.0, 5.0, 3.0]);

v = dnanasum( 0, x, 1 );
t.strictEqual( v, 0.0, 'returns expected value' );
v = dnanasum(0, x, 1);
t.strictEqual(v, 0.0, 'returns expected value');

v = dnanasum( -1, x, 1 );
t.strictEqual( v, 0.0, 'returns expected value' );
v = dnanasum(-1, x, 1);
t.strictEqual(v, 0.0, 'returns expected value');

t.end();
});

tape( 'if provided an `N` parameter equal to `1`, the function returns the first element', function test( t ) {
tape('if provided an `N` parameter equal to `1`, the function returns the first element', function test(t) {
var x;
var v;

x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
x = new Float64Array([1.0, -2.0, -4.0, 5.0, 3.0]);

v = dnanasum( 1, x, 1 );
t.strictEqual( v, 1.0, 'returns expected value' );
v = dnanasum(1, x, 1);
t.strictEqual(v, 1.0, 'returns expected value');

t.end();
});

tape( 'the function supports a `stride` parameter', function test( t ) {
tape('the function supports a `stride` parameter', function test(t) {
var x;
var v;

Expand All @@ -121,13 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
NaN
]);

v = dnanasum( 5, x, 2 );
v = dnanasum(5, x, 2);

t.strictEqual( v, 9.0, 'returns expected value' );
t.strictEqual(v, 9.0, 'returns expected value');
t.end();
});

tape( 'the function supports a negative `stride` parameter', function test( t ) {
tape('the function supports a negative `stride` parameter', function test(t) {
var x;
var v;

Expand All @@ -144,25 +144,30 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
2.0
]);

v = dnanasum( 5, x, -2 );
v = dnanasum(5, x, -2);

t.strictEqual( v, 9.0, 'returns expected value' );
t.strictEqual(v, 9.0, 'returns expected value');
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) {
tape('if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test(t) {
var x;
var v;

x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
x = new Float64Array([1.0, -2.0, -4.0, 5.0, 3.0]);

v = dnanasum(x.length, x, 0);
t.strictEqual(v, 5.0, 'returns expected value');

x = new Float64Array([7.0, -2.0, NaN, 3.0, 5.0]);
v = dnanasum(x.length, x, 0);
t.strictEqual(v, 7.0, 'returns expected value');

v = dnanasum( x.length, x, 0 );
t.strictEqual( v, 5.0, 'returns expected value' );

t.end();
});

tape( 'the function supports view offsets', function test( t ) {
tape('the function supports view offsets', function test(t) {
var x0;
var x1;
var v;
Expand All @@ -181,10 +186,10 @@ tape( 'the function supports view offsets', function test( t ) {
NaN
]);

x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
x1 = new Float64Array(x0.buffer, x0.BYTES_PER_ELEMENT * 1); // start at 2nd element

v = dnanasum( 5, x1, 2 );
t.strictEqual( v, 9.0, 'returns expected value' );
v = dnanasum(5, x1, 2);
t.strictEqual(v, 9.0, 'returns expected value');

t.end();
});
Loading
Loading