|
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 PINF = require( '@stdlib/constants-float32-pinf' ); |
25 | | -var NINF = require( '@stdlib/constants-float32-ninf' ); |
26 | | -var isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' ); |
27 | | -var isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' ); |
28 | | -var isnan = require( '@stdlib/math-base-assert-is-nan' ); |
29 | | -var toBinaryStringf = require( '@stdlib/number-float32-base-to-binary-string' ); |
30 | | -var fromBinaryStringf = require( './../../dist' ); |
31 | | - |
32 | | - |
33 | | -// FIXTURES // |
34 | | - |
35 | | -var small = require( './../fixtures/julia/bits_1e-36_1e-38.json' ); |
36 | | -var medium = require( './../fixtures/julia/bits_-1e3_1e3.json' ); |
37 | | -var large = require( './../fixtures/julia/bits_1e36_1e38.json' ); |
38 | | -var subnormal = require( './../fixtures/julia/bits_1e-39_1e-45.json' ); |
| 24 | +var main = require( './../../dist' ); |
39 | 25 |
|
40 | 26 |
|
41 | 27 | // TESTS // |
42 | 28 |
|
43 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
44 | 30 | t.ok( true, __filename ); |
45 | | - t.strictEqual( typeof fromBinaryStringf, 'function', 'main export is a function' ); |
46 | | - t.end(); |
47 | | -}); |
48 | | - |
49 | | -tape( 'if provided a string with a length other than `32`, the function throws an error', function test( t ) { |
50 | | - var values; |
51 | | - var i; |
52 | | - |
53 | | - values = [ |
54 | | - 'beep', |
55 | | - '1010101', |
56 | | - '', |
57 | | - '101', |
58 | | - '111111111', |
59 | | - '1111111111111111111111111111111', |
60 | | - '111111111111111111111111111111111' |
61 | | - ]; |
62 | | - |
63 | | - for ( i = 0; i < values.length; i++ ) { |
64 | | - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); |
65 | | - } |
66 | | - t.end(); |
67 | | - |
68 | | - function badValue( value ) { |
69 | | - return function badValue() { |
70 | | - fromBinaryStringf( value ); |
71 | | - }; |
72 | | - } |
73 | | -}); |
74 | | - |
75 | | -tape( 'if provided all zeros, the function returns `+0`', function test( t ) { |
76 | | - var v = fromBinaryStringf( toBinaryStringf( 0.0 ) ); |
77 | | - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); |
78 | | - t.end(); |
79 | | -}); |
80 | | - |
81 | | -tape( 'if provided a sign bit of 1 and all zeros, the function returns `-0`', function test( t ) { |
82 | | - var v = fromBinaryStringf( toBinaryStringf( -0.0 ) ); |
83 | | - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); |
84 | | - t.end(); |
85 | | -}); |
86 | | - |
87 | | -tape( 'if provided a bit sequence where all exponent bits are 1s and everything else is 0, the function returns positive infinity', function test( t ) { |
88 | | - t.strictEqual( fromBinaryStringf( toBinaryStringf( PINF ) ), PINF, 'returns +infinity' ); |
89 | | - t.end(); |
90 | | -}); |
91 | | - |
92 | | -tape( 'if provided a bit sequence where the sign bit is 1, all exponent bits are 1s, and everything else is 0, the function returns negative infinity', function test( t ) { |
93 | | - t.strictEqual( fromBinaryStringf( toBinaryStringf( NINF ) ), NINF, 'returns -infinity' ); |
94 | | - t.end(); |
95 | | -}); |
96 | | - |
97 | | -tape( 'if provided a bit sequence where the sign bit may be either 1 or 0, all exponent bits are 1s, and the fraction is not all 0s, the function returns `NaN`', function test( t ) { |
98 | | - var v = fromBinaryStringf( toBinaryStringf( NaN ) ); |
99 | | - t.strictEqual( isnan( v ), true, 'returns NaN' ); |
100 | | - t.end(); |
101 | | -}); |
102 | | - |
103 | | -tape( 'the function creates single-precision floating-point numbers from literal bit representations for small values', function test( t ) { |
104 | | - var expected; |
105 | | - var val; |
106 | | - var x; |
107 | | - var i; |
108 | | - |
109 | | - x = small.x; |
110 | | - expected = small.expected; |
111 | | - for ( i = 0; i < x.length; i++ ) { |
112 | | - val = fromBinaryStringf( x[ i ] ); |
113 | | - t.strictEqual( val, expected[ i ], 'returns a float equal to ' + expected[ i ] + ' from ' + x[ i ] ); |
114 | | - } |
115 | | - t.end(); |
116 | | -}); |
117 | | - |
118 | | -tape( 'the function creates single-precision floating-point numbers from literal bit representations for medium values', function test( t ) { |
119 | | - var expected; |
120 | | - var val; |
121 | | - var x; |
122 | | - var i; |
123 | | - |
124 | | - x = medium.x; |
125 | | - expected = medium.expected; |
126 | | - for ( i = 0; i < x.length; i++ ) { |
127 | | - val = fromBinaryStringf( x[ i ] ); |
128 | | - t.strictEqual( val, expected[ i ], 'returns a float equal to ' + expected[ i ] + ' from ' + x[ i ] ); |
129 | | - } |
130 | | - t.end(); |
131 | | -}); |
132 | | - |
133 | | -tape( 'the function creates single-precision floating-point numbers from literal bit representations for large values', function test( t ) { |
134 | | - var expected; |
135 | | - var val; |
136 | | - var x; |
137 | | - var i; |
138 | | - |
139 | | - x = large.x; |
140 | | - expected = large.expected; |
141 | | - for ( i = 0; i < x.length; i++ ) { |
142 | | - val = fromBinaryStringf( x[ i ] ); |
143 | | - t.strictEqual( val, expected[ i ], 'returns a float equal to ' + expected[ i ] + ' from ' + x[ i ] ); |
144 | | - } |
145 | | - t.end(); |
146 | | -}); |
147 | | - |
148 | | -tape( 'the function creates single-precision floating-point numbers from literal bit representations for subnormal values', function test( t ) { |
149 | | - var expected; |
150 | | - var val; |
151 | | - var x; |
152 | | - var i; |
153 | | - |
154 | | - x = subnormal.x; |
155 | | - expected = subnormal.expected; |
156 | | - for ( i = 0; i < x.length; i++ ) { |
157 | | - val = fromBinaryStringf( x[ i ] ); |
158 | | - t.strictEqual( val, expected[ i ], 'returns a float equal to ' + expected[ i ] + ' from ' + x[ i ] ); |
159 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
160 | 32 | t.end(); |
161 | 33 | }); |
0 commit comments