-
-
Notifications
You must be signed in to change notification settings - Fork 813
/
Copy pathtest.js
111 lines (88 loc) · 2.51 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
// MODULES //
var tape = require( 'tape' );
var MAX_UINT32 = require( '@stdlib/math/constants/uint32-max' );
var binaryString = require( './../lib' );
// FIXTURES //
var small = require( './fixtures/small.json' );
var medium = require( './fixtures/medium.json' );
var large = require( './fixtures/large.json' );
// TESTS //
tape( 'main export is a function', function test( t ) {
t.equal( typeof binaryString, 'function', 'main export is a function' );
t.end();
});
tape( 'the function returns a literal 32-bit unsigned integer representation for 0', function test( t ) {
var expected;
expected = '00000000000000000000000000000000';
t.equal( binaryString(0), expected, 'returns bit literal for 0' );
t.end();
});
tape( 'the function returns a literal 32-bit unsigned integer representation for MAX_UINT32', function test( t ) {
var expected;
expected = '11111111111111111111111111111111';
t.equal( binaryString(MAX_UINT32), expected, 'returns bit literal for MAX_UINT32' );
t.end();
});
tape( 'the function returns literal bit representations for unsigned 32-bit integers (small)', function test( t ) {
var expected;
var str;
var x;
var i;
x = small.x;
expected = small.expected;
for ( i = 0; i < x.length; i++ ) {
str = binaryString( x[ i ] );
t.equal( str, expected[ i ], 'returns bit literal for ' + x[ i ] );
}
t.end();
});
tape( 'the function returns literal bit representations for unsigned 32-bit integers (medium)', function test( t ) {
var expected;
var str;
var x;
var i;
x = medium.x;
expected = medium.expected;
for ( i = 0; i < x.length; i++ ) {
str = binaryString( x[ i ] );
t.equal( str, expected[ i ], 'returns bit literal for ' + x[ i ] );
}
t.end();
});
tape( 'the function returns literal bit representations for unsigned 32-bit integers (large)', function test( t ) {
var expected;
var str;
var x;
var i;
x = large.x;
expected = large.expected;
for ( i = 0; i < x.length; i++ ) {
str = binaryString( x[ i ] );
t.equal( str, expected[ i ], 'returns bit literal for ' + x[ i ] );
}
t.end();
});
tape( 'the function will accept floating-point values, but will interpret the values as unsigned 32-bit integers', function test( t ) {
var values;
var str;
var i;
values = [
1e308,
3.14,
1/3,
1/10,
-0,
-1e-308,
-1e308,
1/0,
1/-0,
NaN
];
for ( i = 0; i < values.length; i++ ) {
str = binaryString( values[i] );
t.equal( typeof str, 'string', 'returns a string' );
t.equal( str.length, 32, 'returns a string of length 32' );
}
t.end();
});