|
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 logspace = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
25 | 25 |
|
26 | 26 |
|
27 | 27 | // TESTS // |
28 | 28 |
|
29 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
30 | 30 | t.ok( true, __filename ); |
31 | | - t.strictEqual( typeof logspace, 'function', 'main export is a function' ); |
32 | | - t.end(); |
33 | | -}); |
34 | | - |
35 | | -tape( 'the function throws an error if the first argument is not a numeric value', function test( t ) { |
36 | | - var values; |
37 | | - var i; |
38 | | - |
39 | | - values = [ |
40 | | - '5', |
41 | | - null, |
42 | | - true, |
43 | | - void 0, |
44 | | - NaN, |
45 | | - [], |
46 | | - {}, |
47 | | - function noop() {} |
48 | | - ]; |
49 | | - |
50 | | - for ( i = 0; i < values.length; i++ ) { |
51 | | - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); |
52 | | - } |
53 | | - t.end(); |
54 | | - |
55 | | - function badValue( value ) { |
56 | | - return function badValue() { |
57 | | - logspace( value, 10 ); |
58 | | - }; |
59 | | - } |
60 | | -}); |
61 | | - |
62 | | -tape( 'the function throws an error if the second argument is not a numeric value', function test( t ) { |
63 | | - var values; |
64 | | - var i; |
65 | | - |
66 | | - values = [ |
67 | | - '5', |
68 | | - null, |
69 | | - true, |
70 | | - void 0, |
71 | | - NaN, |
72 | | - [], |
73 | | - {}, |
74 | | - function noop() {} |
75 | | - ]; |
76 | | - |
77 | | - for ( i = 0; i < values.length; i++ ) { |
78 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
79 | | - } |
80 | | - t.end(); |
81 | | - |
82 | | - function badValue( value ) { |
83 | | - return function badValue() { |
84 | | - logspace( 0, value ); |
85 | | - }; |
86 | | - } |
87 | | -}); |
88 | | - |
89 | | -tape( 'the function throws an error if the `length` value is not a numeric value', function test( t ) { |
90 | | - var values; |
91 | | - var i; |
92 | | - |
93 | | - values = [ |
94 | | - '5', |
95 | | - null, |
96 | | - true, |
97 | | - void 0, |
98 | | - NaN, |
99 | | - [], |
100 | | - {}, |
101 | | - function noop() {} |
102 | | - ]; |
103 | | - |
104 | | - for ( i = 0; i < values.length; i++ ) { |
105 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
106 | | - } |
107 | | - t.end(); |
108 | | - |
109 | | - function badValue( value ) { |
110 | | - return function badValue() { |
111 | | - logspace( 0, 10, value ); |
112 | | - }; |
113 | | - } |
114 | | -}); |
115 | | - |
116 | | -tape( 'the function returns a logarithmically spaced array', function test( t ) { |
117 | | - var expected; |
118 | | - var actual; |
119 | | - var a; |
120 | | - var b; |
121 | | - |
122 | | - a = 0; |
123 | | - b = 3; |
124 | | - |
125 | | - // Default behavior: |
126 | | - actual = logspace( a, b ); |
127 | | - t.strictEqual( actual.length, 10 ); |
128 | | - t.strictEqual( actual[0], 1 ); |
129 | | - t.strictEqual( actual[actual.length-1], 1000 ); |
130 | | - |
131 | | - // Specify the length: |
132 | | - actual = logspace( a, b, 10 ); |
133 | | - t.strictEqual( actual.length, 10 ); |
134 | | - t.strictEqual( actual[0], 1 ); |
135 | | - t.strictEqual( actual[actual.length-1], 1000 ); |
136 | | - |
137 | | - // Verify correct values: |
138 | | - actual = logspace( a, b, 4 ); |
139 | | - expected = [ 1, 10, 100, 1000 ]; |
140 | | - |
141 | | - t.deepEqual( actual, expected ); |
142 | | - |
143 | | - // Decrement: |
144 | | - actual = logspace( b, a, 4 ); |
145 | | - expected = [ 1000, 100, 10, 1 ]; |
146 | | - |
147 | | - t.deepEqual( actual, expected ); |
148 | | - t.end(); |
149 | | -}); |
150 | | - |
151 | | -tape( 'if the length is set to `0`, the function returns an empty array', function test( t ) { |
152 | | - t.deepEqual( logspace(0, 10, 0), [] ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
153 | 32 | t.end(); |
154 | 33 | }); |
0 commit comments