|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 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 noop = require( '@stdlib/utils-noop' );
2934
|
25 |
| -var Float64Array = require( '@stdlib/array-float64' ); |
26 |
| -var noneBy = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
27 | 25 |
|
28 | 26 |
|
29 | 27 | // TESTS //
|
30 | 28 |
|
31 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
32 | 30 | t.ok( true, __filename );
|
33 |
| - t.strictEqual( typeof noneBy, 'function', 'main export is a function' ); |
34 |
| - t.end(); |
35 |
| -}); |
36 |
| - |
37 |
| -tape( 'the function throws an error if not provided a collection', function test( t ) { |
38 |
| - var values; |
39 |
| - var i; |
40 |
| - |
41 |
| - values = [ |
42 |
| - '5', |
43 |
| - 5, |
44 |
| - NaN, |
45 |
| - true, |
46 |
| - false, |
47 |
| - null, |
48 |
| - void 0, |
49 |
| - {}, |
50 |
| - function noop() {}, |
51 |
| - /.*/, |
52 |
| - new Date() |
53 |
| - ]; |
54 |
| - |
55 |
| - for ( i = 0; i < values.length; i++ ) { |
56 |
| - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); |
57 |
| - } |
58 |
| - t.end(); |
59 |
| - |
60 |
| - function badValue( value ) { |
61 |
| - return function badValue() { |
62 |
| - noneBy( value, noop ); |
63 |
| - }; |
64 |
| - } |
65 |
| -}); |
66 |
| - |
67 |
| -tape( 'the function throws an error if not provided a predicate function', function test( t ) { |
68 |
| - var values; |
69 |
| - var i; |
70 |
| - |
71 |
| - values = [ |
72 |
| - '5', |
73 |
| - 5, |
74 |
| - NaN, |
75 |
| - true, |
76 |
| - false, |
77 |
| - null, |
78 |
| - void 0, |
79 |
| - {}, |
80 |
| - [], |
81 |
| - /.*/, |
82 |
| - new Date() |
83 |
| - ]; |
84 |
| - |
85 |
| - for ( i = 0; i < values.length; i++ ) { |
86 |
| - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); |
87 |
| - } |
88 |
| - t.end(); |
89 |
| - |
90 |
| - function badValue( value ) { |
91 |
| - return function badValue() { |
92 |
| - noneBy( [ 1, 2, 3 ], value ); |
93 |
| - }; |
94 |
| - } |
95 |
| -}); |
96 |
| - |
97 |
| -tape( 'if provided an empty collection, the function returns `true`', function test( t ) { |
98 |
| - var bool; |
99 |
| - var arr; |
100 |
| - |
101 |
| - function foo() { |
102 |
| - t.fail( 'should not be invoked' ); |
103 |
| - } |
104 |
| - arr = []; |
105 |
| - bool = noneBy( arr, foo ); |
106 |
| - |
107 |
| - t.strictEqual( bool, true, 'returns true' ); |
108 |
| - t.end(); |
109 |
| -}); |
110 |
| - |
111 |
| -tape( 'the function returns `true` if all elements fail a test (array)', function test( t ) { |
112 |
| - var bool; |
113 |
| - var arr; |
114 |
| - |
115 |
| - arr = [ -1, -2, -3 ]; |
116 |
| - |
117 |
| - function isPositive( value ) { |
118 |
| - return ( value > 0 ); |
119 |
| - } |
120 |
| - |
121 |
| - bool = noneBy( arr, isPositive ); |
122 |
| - |
123 |
| - t.strictEqual( bool, true, 'returns true' ); |
124 |
| - t.end(); |
125 |
| -}); |
126 |
| - |
127 |
| -tape( 'the function returns `false` if one or more elements pass a test (array)', function test( t ) { |
128 |
| - var bool; |
129 |
| - var arr; |
130 |
| - |
131 |
| - arr = [ -1, 2, -3 ]; |
132 |
| - |
133 |
| - function isPositive( value ) { |
134 |
| - return ( value > 0 ); |
135 |
| - } |
136 |
| - |
137 |
| - bool = noneBy( arr, isPositive ); |
138 |
| - |
139 |
| - t.strictEqual( bool, false, 'returns false' ); |
140 |
| - t.end(); |
141 |
| -}); |
142 |
| - |
143 |
| -tape( 'the function returns `true` if all elements fail a test (array-like object)', function test( t ) { |
144 |
| - var bool; |
145 |
| - var arr; |
146 |
| - |
147 |
| - arr = { |
148 |
| - 'length': 3, |
149 |
| - '0': -1, |
150 |
| - '1': -2, |
151 |
| - '2': -3 |
152 |
| - }; |
153 |
| - |
154 |
| - function isPositive( value ) { |
155 |
| - return ( value > 0 ); |
156 |
| - } |
157 |
| - |
158 |
| - bool = noneBy( arr, isPositive ); |
159 |
| - |
160 |
| - t.strictEqual( bool, true, 'returns true' ); |
161 |
| - t.end(); |
162 |
| -}); |
163 |
| - |
164 |
| -tape( 'the function returns `false` if one or more elements pass a test (array-like object)', function test( t ) { |
165 |
| - var bool; |
166 |
| - var arr; |
167 |
| - |
168 |
| - arr = { |
169 |
| - 'length': 3, |
170 |
| - '0': -1, |
171 |
| - '1': 2, |
172 |
| - '2': -3 |
173 |
| - }; |
174 |
| - |
175 |
| - function isPositive( value ) { |
176 |
| - return ( value > 0 ); |
177 |
| - } |
178 |
| - |
179 |
| - bool = noneBy( arr, isPositive ); |
180 |
| - |
181 |
| - t.strictEqual( bool, false, 'returns false' ); |
182 |
| - t.end(); |
183 |
| -}); |
184 |
| - |
185 |
| -tape( 'the function returns `true` if all elements fail a test (typed array)', function test( t ) { |
186 |
| - var bool; |
187 |
| - var arr; |
188 |
| - |
189 |
| - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); |
190 |
| - |
191 |
| - function isPositive( value ) { |
192 |
| - return ( value > 0 ); |
193 |
| - } |
194 |
| - |
195 |
| - bool = noneBy( arr, isPositive ); |
196 |
| - |
197 |
| - t.strictEqual( bool, true, 'returns true' ); |
198 |
| - t.end(); |
199 |
| -}); |
200 |
| - |
201 |
| -tape( 'the function returns `false` if one or more elements pass a test (typed array)', function test( t ) { |
202 |
| - var bool; |
203 |
| - var arr; |
204 |
| - |
205 |
| - arr = new Float64Array( [ -1.0, 2.0, -3.0 ] ); |
206 |
| - |
207 |
| - function isPositive( value ) { |
208 |
| - return ( value > 0 ); |
209 |
| - } |
210 |
| - |
211 |
| - bool = noneBy( arr, isPositive ); |
212 |
| - |
213 |
| - t.strictEqual( bool, false, 'returns false' ); |
214 |
| - t.end(); |
215 |
| -}); |
216 |
| - |
217 |
| -tape( 'the function supports providing an execution context', function test( t ) { |
218 |
| - var bool; |
219 |
| - var ctx; |
220 |
| - var arr; |
221 |
| - |
222 |
| - function sum( value ) { |
223 |
| - /* eslint-disable no-invalid-this */ |
224 |
| - if ( value < 0 ) { |
225 |
| - return false; |
226 |
| - } |
227 |
| - this.sum += value; |
228 |
| - this.count += 1; |
229 |
| - return false; |
230 |
| - } |
231 |
| - |
232 |
| - ctx = { |
233 |
| - 'sum': 0, |
234 |
| - 'count': 0 |
235 |
| - }; |
236 |
| - arr = [ 1.0, 2.0, 3.0 ]; |
237 |
| - |
238 |
| - bool = noneBy( arr, sum, ctx ); |
239 |
| - |
240 |
| - t.strictEqual( bool, true, 'returns true' ); |
241 |
| - t.strictEqual( ctx.sum/ctx.count, 2.0, 'expected result' ); |
242 |
| - |
243 |
| - t.end(); |
244 |
| -}); |
245 |
| - |
246 |
| -tape( 'the function provides basic support for dynamic arrays', function test( t ) { |
247 |
| - var bool; |
248 |
| - var arr; |
249 |
| - |
250 |
| - arr = [ 1, 2, 3 ]; |
251 |
| - |
252 |
| - function isNegative( value, index, collection ) { |
253 |
| - if ( index === collection.length-1 && collection.length < 10 ) { |
254 |
| - collection.push( index+2 ); |
255 |
| - } |
256 |
| - return ( value < 0 ); |
257 |
| - } |
258 |
| - |
259 |
| - bool = noneBy( arr, isNegative ); |
260 |
| - |
261 |
| - t.deepEqual( arr, [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], 'expected result' ); |
262 |
| - t.strictEqual( bool, true, 'returns true' ); |
263 |
| - |
264 |
| - t.end(); |
265 |
| -}); |
266 |
| - |
267 |
| -tape( 'the function does not skip empty elements', function test( t ) { |
268 |
| - var expected; |
269 |
| - var bool; |
270 |
| - var arr; |
271 |
| - |
272 |
| - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays |
273 |
| - expected = [ 1, void 0, void 0, 4 ]; |
274 |
| - |
275 |
| - function verify( value, index ) { |
276 |
| - t.strictEqual( value, expected[ index ], 'provides expected value' ); |
277 |
| - return false; |
278 |
| - } |
279 |
| - |
280 |
| - bool = noneBy( arr, verify ); |
281 |
| - |
282 |
| - t.strictEqual( bool, true, 'returns true' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
283 | 32 | t.end();
|
284 | 33 | });
|
0 commit comments