Skip to content

Commit dcc8d37

Browse files
feat(array/fixed-endian-float64): add comprehensive unit tests
- Add tests for constructor functionality - Add tests for endianness validation - Add tests for various initialization methods - Resolves TODO in test.js
1 parent 9d84704 commit dcc8d37

File tree

1 file changed

+108
-4
lines changed
  • lib/node_modules/@stdlib/array/fixed-endian-float64/test

1 file changed

+108
-4
lines changed

lib/node_modules/@stdlib/array/fixed-endian-float64/test/test.js

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,15 +21,119 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24-
var ctor = require( './../lib' );
24+
var Float64ArrayFE = require( './../lib' );
2525

2626

2727
// TESTS //
2828

2929
tape( 'main export is a function', function test( t ) {
3030
t.ok( true, __filename );
31-
t.strictEqual( typeof ctor, 'function', 'main export is a function' );
31+
t.strictEqual( typeof Float64ArrayFE, 'function', 'main export is a function' );
3232
t.end();
3333
});
3434

35-
// TODO: add tests
35+
tape( 'the function is a constructor', function test( t ) {
36+
var arr = new Float64ArrayFE( 'little-endian' );
37+
t.strictEqual( arr instanceof Float64ArrayFE, true, 'returns an instance' );
38+
t.end();
39+
});
40+
41+
tape( 'the constructor throws an error if not provided a valid endianness as the first argument', function test( t ) {
42+
var values;
43+
var i;
44+
45+
values = [
46+
'foo',
47+
'bar',
48+
'beep',
49+
'boop',
50+
5,
51+
NaN,
52+
true,
53+
false,
54+
null,
55+
void 0,
56+
[],
57+
{},
58+
function noop() {}
59+
];
60+
61+
for ( i = 0; i < values.length; i++ ) {
62+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
63+
}
64+
t.end();
65+
66+
function badValue( value ) {
67+
return function badValue() {
68+
return new Float64ArrayFE( value );
69+
};
70+
}
71+
});
72+
73+
tape( 'the constructor returns an instance with a `length` property', function test( t ) {
74+
var arr = new Float64ArrayFE( 'little-endian', 10 );
75+
t.strictEqual( arr.length, 10, 'has length property' );
76+
t.end();
77+
});
78+
79+
tape( 'the constructor supports creating a zero-length array', function test( t ) {
80+
var arr = new Float64ArrayFE( 'big-endian', 0 );
81+
t.strictEqual( arr.length, 0, 'has zero length' );
82+
t.end();
83+
});
84+
85+
tape( 'the constructor supports little-endian byte order', function test( t ) {
86+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );
87+
t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' );
88+
t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' );
89+
t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' );
90+
t.end();
91+
});
92+
93+
tape( 'the constructor supports big-endian byte order', function test( t ) {
94+
var arr = new Float64ArrayFE( 'big-endian', [ 1.0, 2.0, 3.0 ] );
95+
t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' );
96+
t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' );
97+
t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' );
98+
t.end();
99+
});
100+
101+
tape( 'the constructor supports creating an array from an array-like object', function test( t ) {
102+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );
103+
t.strictEqual( arr.length, 3, 'has expected length' );
104+
t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' );
105+
t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' );
106+
t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' );
107+
t.end();
108+
});
109+
110+
tape( 'the constructor supports creating an array from a typed array', function test( t ) {
111+
var buf = new Float64Array( [ 1.0, 2.0, 3.0 ] );
112+
var arr = new Float64ArrayFE( 'big-endian', buf );
113+
t.strictEqual( arr.length, 3, 'has expected length' );
114+
t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' );
115+
t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' );
116+
t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' );
117+
t.end();
118+
});
119+
120+
tape( 'the constructor supports creating an array from an ArrayBuffer', function test( t ) {
121+
var buf = new ArrayBuffer( 24 ); // 3 * 8 bytes
122+
var arr = new Float64ArrayFE( 'little-endian', buf );
123+
t.strictEqual( arr.length, 3, 'has expected length' );
124+
t.end();
125+
});
126+
127+
tape( 'the constructor supports creating an array from an ArrayBuffer with a byte offset', function test( t ) {
128+
var buf = new ArrayBuffer( 32 );
129+
var arr = new Float64ArrayFE( 'big-endian', buf, 8 );
130+
t.strictEqual( arr.length, 3, 'has expected length' );
131+
t.end();
132+
});
133+
134+
tape( 'the constructor supports creating an array from an ArrayBuffer with a byte offset and length', function test( t ) {
135+
var buf = new ArrayBuffer( 32 );
136+
var arr = new Float64ArrayFE( 'little-endian', buf, 8, 2 );
137+
t.strictEqual( arr.length, 2, 'has expected length' );
138+
t.end();
139+
});

0 commit comments

Comments
 (0)