1
1
/**
2
2
* @license Apache-2.0
3
3
*
4
- * Copyright (c) 2024 The Stdlib Authors.
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
5
*
6
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
7
* you may not use this file except in compliance with the License.
21
21
// MODULES //
22
22
23
23
var tape = require ( 'tape' ) ;
24
- var ctor = require ( './../lib' ) ;
24
+ var Float64ArrayFE = require ( './../lib' ) ;
25
25
26
26
27
27
// TESTS //
28
28
29
29
tape ( 'main export is a function' , function test ( t ) {
30
30
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' ) ;
32
32
t . end ( ) ;
33
33
} ) ;
34
34
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