|
1 | 1 | /** |
2 | 2 | * @license Apache-2.0 |
3 | 3 | * |
4 | | -* Copyright (c) 2019 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 array2iterator = require( '@stdlib/array-to-iterator' ); |
25 | | -var iterEmpty = require( '@stdlib/iter-empty' ); |
26 | | -var isnan = require( '@stdlib/math-base-assert-is-nan' ); |
27 | | -var iterstdev = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
28 | 25 |
|
29 | 26 |
|
30 | 27 | // TESTS // |
31 | 28 |
|
32 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
33 | 30 | t.ok( true, __filename ); |
34 | | - t.strictEqual( typeof iterstdev, 'function', 'main export is a function' ); |
35 | | - t.end(); |
36 | | -}); |
37 | | - |
38 | | -tape( 'the function throws an error if not provided an iterator', function test( t ) { |
39 | | - var values; |
40 | | - var i; |
41 | | - |
42 | | - values = [ |
43 | | - '5', |
44 | | - 5, |
45 | | - NaN, |
46 | | - true, |
47 | | - false, |
48 | | - null, |
49 | | - void 0, |
50 | | - {}, |
51 | | - [], |
52 | | - function noop() {} |
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 | | - iterstdev( value ); |
63 | | - }; |
64 | | - } |
65 | | -}); |
66 | | - |
67 | | -tape( 'the function throws an error if not provided an iterator (mean)', 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 | | - function noop() {} |
82 | | - ]; |
83 | | - |
84 | | - for ( i = 0; i < values.length; i++ ) { |
85 | | - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); |
86 | | - } |
87 | | - t.end(); |
88 | | - |
89 | | - function badValue( value ) { |
90 | | - return function badValue() { |
91 | | - iterstdev( value, 0.0 ); |
92 | | - }; |
93 | | - } |
94 | | -}); |
95 | | - |
96 | | -tape( 'the function throws an error if provided a non-numeric second argument', function test( t ) { |
97 | | - var values; |
98 | | - var i; |
99 | | - |
100 | | - values = [ |
101 | | - '5', |
102 | | - true, |
103 | | - false, |
104 | | - null, |
105 | | - void 0, |
106 | | - {}, |
107 | | - [], |
108 | | - function noop() {} |
109 | | - ]; |
110 | | - |
111 | | - for ( i = 0; i < values.length; i++ ) { |
112 | | - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); |
113 | | - } |
114 | | - t.end(); |
115 | | - |
116 | | - function badValue( value ) { |
117 | | - return function badValue() { |
118 | | - iterstdev( array2iterator( [ 1, 2, 3 ] ), value ); |
119 | | - }; |
120 | | - } |
121 | | -}); |
122 | | - |
123 | | -tape( 'the function computes the corrected sample standard deviation', function test( t ) { |
124 | | - var arr; |
125 | | - var v; |
126 | | - |
127 | | - arr = array2iterator( [ 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ] ); |
128 | | - v = iterstdev( arr ); |
129 | | - |
130 | | - // Tested against Julia: |
131 | | - t.strictEqual( v, 0.8944271909999159, 'returns expected value' ); |
132 | | - t.end(); |
133 | | -}); |
134 | | - |
135 | | -tape( 'the function computes the corrected sample standard deviation (known mean)', function test( t ) { |
136 | | - var arr; |
137 | | - var v; |
138 | | - |
139 | | - arr = array2iterator( [ 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ] ); |
140 | | - v = iterstdev( arr, 3.0 ); |
141 | | - |
142 | | - // Tested against Julia: |
143 | | - t.strictEqual( v, 0.816496580927726, 'returns expected value' ); |
144 | | - t.end(); |
145 | | -}); |
146 | | - |
147 | | -tape( 'the function returns `null` if provided an "empty" iterator', function test( t ) { |
148 | | - var v = iterstdev( iterEmpty() ); |
149 | | - t.strictEqual( v, null, 'returns expected value' ); |
150 | | - t.end(); |
151 | | -}); |
152 | | - |
153 | | -tape( 'the function returns `null` if provided an "empty" iterator (known mean)', function test( t ) { |
154 | | - var v = iterstdev( iterEmpty(), 0.0 ); |
155 | | - t.strictEqual( v, null, 'returns expected value' ); |
156 | | - t.end(); |
157 | | -}); |
158 | | - |
159 | | -tape( 'the function returns `NaN` if an iterated value is non-numeric', function test( t ) { |
160 | | - var arr; |
161 | | - var v; |
162 | | - |
163 | | - arr = array2iterator( [ 1.0, 2.0, '3.0', 4.0 ] ); |
164 | | - v = iterstdev( arr ); |
165 | | - |
166 | | - t.strictEqual( isnan( v ), true, 'returns expected value' ); |
167 | | - |
168 | | - arr = array2iterator( [ 1.0, 2.0, NaN, 4.0 ] ); |
169 | | - v = iterstdev( arr ); |
170 | | - |
171 | | - t.strictEqual( isnan( v ), true, 'returns expected value' ); |
172 | | - |
173 | | - arr = array2iterator( [ 1.0, 2.0, '3.0', 4.0 ] ); |
174 | | - v = iterstdev( arr, 2.5 ); |
175 | | - |
176 | | - t.strictEqual( isnan( v ), true, 'returns expected value' ); |
177 | | - |
178 | | - arr = array2iterator( [ 1.0, 2.0, NaN, 4.0 ] ); |
179 | | - v = iterstdev( arr, 2.5 ); |
180 | | - |
181 | | - t.strictEqual( isnan( v ), true, 'returns expected value' ); |
182 | | - t.end(); |
183 | | -}); |
184 | | - |
185 | | -tape( 'the function returns `NaN` if a provided mean is `NaN`', function test( t ) { |
186 | | - var arr; |
187 | | - var v; |
188 | | - |
189 | | - arr = array2iterator( [ 1.0, 2.0, 3.0, 4.0 ] ); |
190 | | - v = iterstdev( arr, NaN ); |
191 | | - |
192 | | - t.strictEqual( isnan( v ), true, 'returns expected value' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
193 | 32 | t.end(); |
194 | 33 | }); |
0 commit comments