|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2020 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 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 randu = require( '@stdlib/random-iter-randu' ); |
25 |
| -var abs2 = require( '@stdlib/math-base-special-abs2' ); |
26 |
| -var linspace = require( '@stdlib/iter-linspace' ); |
27 |
| -var array2iterator = require( '@stdlib/array-to-iterator' ); |
28 |
| -var iterAbs2 = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
29 | 25 |
|
30 | 26 |
|
31 | 27 | // TESTS //
|
32 | 28 |
|
33 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
34 | 30 | t.ok( true, __filename );
|
35 |
| - t.strictEqual( typeof iterAbs2, 'function', 'main export is a function' ); |
36 |
| - t.end(); |
37 |
| -}); |
38 |
| - |
39 |
| -tape( 'the function throws an error if provided an iterator argument which is not an iterator protocol-compliant object', function test( t ) { |
40 |
| - var values; |
41 |
| - var i; |
42 |
| - |
43 |
| - values = [ |
44 |
| - '5', |
45 |
| - 5, |
46 |
| - NaN, |
47 |
| - true, |
48 |
| - false, |
49 |
| - null, |
50 |
| - void 0, |
51 |
| - {}, |
52 |
| - [], |
53 |
| - function noop() {} |
54 |
| - ]; |
55 |
| - |
56 |
| - for ( i = 0; i < values.length; i++ ) { |
57 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
58 |
| - } |
59 |
| - t.end(); |
60 |
| - |
61 |
| - function badValue( value ) { |
62 |
| - return function badValue() { |
63 |
| - iterAbs2( value ); |
64 |
| - }; |
65 |
| - } |
66 |
| -}); |
67 |
| - |
68 |
| -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { |
69 |
| - var it; |
70 |
| - var r; |
71 |
| - var i; |
72 |
| - |
73 |
| - it = iterAbs2( randu() ); |
74 |
| - t.equal( it.next.length, 0, 'has zero arity' ); |
75 |
| - |
76 |
| - for ( i = 0; i < 100; i++ ) { |
77 |
| - r = it.next(); |
78 |
| - t.equal( typeof r.value, 'number', 'returns a number' ); |
79 |
| - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); |
80 |
| - } |
81 |
| - t.end(); |
82 |
| -}); |
83 |
| - |
84 |
| -tape( 'the function returns an iterator protocol-compliant object which computes the squared absolute value of each iterated value', function test( t ) { |
85 |
| - var expected; |
86 |
| - var it; |
87 |
| - var N; |
88 |
| - var x; |
89 |
| - var r; |
90 |
| - var i; |
91 |
| - |
92 |
| - N = 101; |
93 |
| - it = iterAbs2( linspace( -10.0, 10.0, N ) ); |
94 |
| - t.equal( it.next.length, 0, 'has zero arity' ); |
95 |
| - |
96 |
| - x = linspace( -10.0, 10.0, N ); |
97 |
| - for ( i = 0; i < N; i++ ) { |
98 |
| - r = it.next(); |
99 |
| - expected = abs2( x.next().value ); |
100 |
| - t.equal( r.value, expected, 'returns expected value' ); |
101 |
| - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); |
102 |
| - } |
103 |
| - r = it.next(); |
104 |
| - t.equal( r.value, void 0, 'returns expected value' ); |
105 |
| - t.equal( r.done, true, 'returns expected value' ); |
106 |
| - |
107 |
| - t.end(); |
108 |
| -}); |
109 |
| - |
110 |
| -tape( 'the function returns an iterator protocol-compliant object which returns `NaN` if provided a non-numeric value', function test( t ) { |
111 |
| - var expected; |
112 |
| - var values; |
113 |
| - var actual; |
114 |
| - var it; |
115 |
| - var r; |
116 |
| - var i; |
117 |
| - |
118 |
| - values = [ 'abc', null, true, false, [], {} ]; |
119 |
| - expected = [ |
120 |
| - { |
121 |
| - 'value': NaN, |
122 |
| - 'done': false |
123 |
| - }, |
124 |
| - { |
125 |
| - 'value': NaN, |
126 |
| - 'done': false |
127 |
| - }, |
128 |
| - { |
129 |
| - 'value': NaN, |
130 |
| - 'done': false |
131 |
| - }, |
132 |
| - { |
133 |
| - 'value': NaN, |
134 |
| - 'done': false |
135 |
| - }, |
136 |
| - { |
137 |
| - 'value': NaN, |
138 |
| - 'done': false |
139 |
| - }, |
140 |
| - { |
141 |
| - 'value': NaN, |
142 |
| - 'done': false |
143 |
| - }, |
144 |
| - { |
145 |
| - 'done': true |
146 |
| - } |
147 |
| - ]; |
148 |
| - |
149 |
| - it = iterAbs2( array2iterator( values ) ); |
150 |
| - t.equal( it.next.length, 0, 'has zero arity' ); |
151 |
| - |
152 |
| - for ( i = 0; i < expected.length; i++ ) { |
153 |
| - actual = it.next(); |
154 |
| - r = expected[ i ].value; |
155 |
| - if ( r === r ) { |
156 |
| - t.equal( actual.value, r, 'returns expected value' ); |
157 |
| - } else { |
158 |
| - t.notEqual( actual.value, actual.value, 'returns expected value' ); |
159 |
| - } |
160 |
| - t.equal( actual.done, expected[ i ].done, 'returns a boolean' ); |
161 |
| - } |
162 |
| - t.end(); |
163 |
| -}); |
164 |
| - |
165 |
| -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { |
166 |
| - var it; |
167 |
| - var r; |
168 |
| - |
169 |
| - it = iterAbs2( randu() ); |
170 |
| - |
171 |
| - r = it.next(); |
172 |
| - t.equal( typeof r.value, 'number', 'returns a number' ); |
173 |
| - t.equal( r.done, false, 'returns expected value' ); |
174 |
| - |
175 |
| - r = it.next(); |
176 |
| - t.equal( typeof r.value, 'number', 'returns a number' ); |
177 |
| - t.equal( r.done, false, 'returns expected value' ); |
178 |
| - |
179 |
| - r = it.return(); |
180 |
| - t.equal( r.value, void 0, 'returns expected value' ); |
181 |
| - t.equal( r.done, true, 'returns expected value' ); |
182 |
| - |
183 |
| - r = it.next(); |
184 |
| - t.equal( r.value, void 0, 'returns expected value' ); |
185 |
| - t.equal( r.done, true, 'returns expected value' ); |
186 |
| - |
187 |
| - t.end(); |
188 |
| -}); |
189 |
| - |
190 |
| -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { |
191 |
| - var it; |
192 |
| - var r; |
193 |
| - |
194 |
| - it = iterAbs2( randu() ); |
195 |
| - |
196 |
| - r = it.next(); |
197 |
| - t.equal( typeof r.value, 'number', 'returns a number' ); |
198 |
| - t.equal( r.done, false, 'returns expected value' ); |
199 |
| - |
200 |
| - r = it.next(); |
201 |
| - t.equal( typeof r.value, 'number', 'returns a number' ); |
202 |
| - t.equal( r.done, false, 'returns expected value' ); |
203 |
| - |
204 |
| - r = it.return( 'finished' ); |
205 |
| - t.equal( r.value, 'finished', 'returns expected value' ); |
206 |
| - t.equal( r.done, true, 'returns expected value' ); |
207 |
| - |
208 |
| - r = it.next(); |
209 |
| - t.equal( r.value, void 0, 'returns expected value' ); |
210 |
| - t.equal( r.done, true, 'returns expected value' ); |
211 |
| - |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
212 | 32 | t.end();
|
213 | 33 | });
|
0 commit comments