|
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 objectKeys = require( '@stdlib/utils-keys' ); |
25 | | -var PINF = require( '@stdlib/constants-float64-pinf' ); |
26 | | -var NINF = require( '@stdlib/constants-float64-ninf' ); |
27 | | -var isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' ); |
28 | | -var isnan = require( '@stdlib/math-base-assert-is-nan' ); |
29 | | -var toBinaryString = require( '@stdlib/number-float64-base-to-binary-string' ); |
30 | | -var fromBinaryString = require( './../../dist' ); |
31 | | - |
32 | | - |
33 | | -// FIXTURES // |
34 | | - |
35 | | -var small = require( './../fixtures/julia/bits_1e-200_1e-308.json' ); |
36 | | -var medium = require( './../fixtures/julia/bits_-1e3_1e3.json' ); |
37 | | -var large = require( './../fixtures/julia/bits_1e200_1e308.json' ); |
38 | | -var subnormal = require( './../fixtures/julia/bits_1e-310_5e-324.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 fromBinaryString, '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 | | - '11111111111111111111111111111111111111111111111111111111111111111', |
62 | | - '111111111111111111111111111111111111111111111111111111111111111' |
63 | | - ]; |
64 | | - |
65 | | - for ( i = 0; i < values.length; i++ ) { |
66 | | - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); |
67 | | - } |
68 | | - t.end(); |
69 | | - |
70 | | - function badValue( value ) { |
71 | | - return function badValue() { |
72 | | - fromBinaryString( value ); |
73 | | - }; |
74 | | - } |
75 | | -}); |
76 | | - |
77 | | -tape( 'if provided all zeros, the function returns `+0`', function test( t ) { |
78 | | - t.strictEqual( fromBinaryString( toBinaryString( 0.0 ) ), 0.0, 'returns +0' ); |
79 | | - t.end(); |
80 | | -}); |
81 | | - |
82 | | -tape( 'if provided a sign bit of 1 and all zeros, the function returns `-0`', function test( t ) { |
83 | | - var v = fromBinaryString( toBinaryString( -0.0 ) ); |
84 | | - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); |
85 | | - t.end(); |
86 | | -}); |
87 | | - |
88 | | -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 ) { |
89 | | - t.strictEqual( fromBinaryString( toBinaryString( PINF ) ), PINF, 'returns +infinity' ); |
90 | | - t.end(); |
91 | | -}); |
92 | | - |
93 | | -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 ) { |
94 | | - t.strictEqual( fromBinaryString( toBinaryString( NINF ) ), NINF, 'returns -infinity' ); |
95 | | - t.end(); |
96 | | -}); |
97 | | - |
98 | | -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 ) { |
99 | | - var v = fromBinaryString( toBinaryString( NaN ) ); |
100 | | - t.strictEqual( isnan( v ), true, 'returns NaN' ); |
101 | | - t.end(); |
102 | | -}); |
103 | | - |
104 | | -tape( 'the function creates double-precision floating-point numbers from literal bit representations for small values', function test( t ) { |
105 | | - var keys; |
106 | | - var key; |
107 | | - var val; |
108 | | - var x; |
109 | | - var i; |
110 | | - |
111 | | - keys = objectKeys( small ); |
112 | | - for ( i = 0; i < keys.length; i++ ) { |
113 | | - key = keys[ i ]; |
114 | | - x = fromBinaryString( key ); |
115 | | - val = parseFloat( small[ key ] ); |
116 | | - t.strictEqual( x, val, 'returns a double equal to ' + val + ' from ' + key ); |
117 | | - } |
118 | | - t.end(); |
119 | | -}); |
120 | | - |
121 | | -tape( 'the function creates double-precision floating-point numbers from literal bit representations for medium values', function test( t ) { |
122 | | - var keys; |
123 | | - var key; |
124 | | - var val; |
125 | | - var x; |
126 | | - var i; |
127 | | - |
128 | | - keys = objectKeys( medium ); |
129 | | - for ( i = 0; i < keys.length; i++ ) { |
130 | | - key = keys[ i ]; |
131 | | - x = fromBinaryString( key ); |
132 | | - val = parseFloat( medium[ key ] ); |
133 | | - t.strictEqual( x, val, 'returns a double equal to ' + val + ' from ' + key ); |
134 | | - } |
135 | | - t.end(); |
136 | | -}); |
137 | | - |
138 | | -tape( 'the function creates double-precision floating-point numbers from literal bit representations for large values', function test( t ) { |
139 | | - var keys; |
140 | | - var key; |
141 | | - var val; |
142 | | - var x; |
143 | | - var i; |
144 | | - |
145 | | - keys = objectKeys( large ); |
146 | | - for ( i = 0; i < keys.length; i++ ) { |
147 | | - key = keys[ i ]; |
148 | | - x = fromBinaryString( key ); |
149 | | - val = parseFloat( large[ key ] ); |
150 | | - t.strictEqual( x, val, 'returns a double equal to ' + val + ' from ' + key ); |
151 | | - } |
152 | | - t.end(); |
153 | | -}); |
154 | | - |
155 | | -tape( 'the function creates double-precision floating-point numbers from literal bit representations for subnormal values', function test( t ) { |
156 | | - var keys; |
157 | | - var key; |
158 | | - var val; |
159 | | - var x; |
160 | | - var i; |
161 | | - |
162 | | - keys = objectKeys( subnormal ); |
163 | | - for ( i = 0; i < keys.length; i++ ) { |
164 | | - key = keys[ i ]; |
165 | | - x = fromBinaryString( key ); |
166 | | - val = parseFloat( subnormal[ key ] ); |
167 | | - t.strictEqual( x, val, 'returns a double equal to ' + val + ' from ' + key ); |
168 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
169 | 32 | t.end(); |
170 | 33 | }); |
0 commit comments