|
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 proxyquire = require( 'proxyquire' ); |
25 |
| -var Float32Array = require( '@stdlib/array-float32' ); |
26 |
| -var Number = require( '@stdlib/number-ctor' ); |
27 |
| -var detect = require( './../../dist' ); |
28 |
| - |
29 |
| - |
30 |
| -// VARIABLES // |
31 |
| - |
32 |
| -var hasFloat32Array = ( typeof Float32Array === 'function' ); |
| 24 | +var main = require( './../../dist' ); |
33 | 25 |
|
34 | 26 |
|
35 | 27 | // TESTS //
|
36 | 28 |
|
37 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
38 | 30 | t.ok( true, __filename );
|
39 |
| -t.strictEqual( typeof detect, 'function', 'main export is a function' ); |
| 31 | +t.strictEqual( main !== void 0, true, 'main export is defined' ); |
40 | 32 | t.end();
|
41 | 33 | });
|
42 |
| - |
43 |
| -tape( 'feature detection result is a boolean', function test( t ) { |
44 |
| -t.strictEqual( typeof detect(), 'boolean', 'detection result is a boolean' ); |
45 |
| -t.end(); |
46 |
| -}); |
47 |
| - |
48 |
| -tape( 'if `Float32Array` is supported, detection result is `true`', function test( t ) { |
49 |
| -var mocked; |
50 |
| -if ( hasFloat32Array ) { |
51 |
| -t.strictEqual( detect(), true, 'detection result is `true`' ); |
52 |
| -} else { |
53 |
| -t.strictEqual( detect(), false, 'detection result is `false`' ); |
54 |
| -} |
55 |
| -mocked = proxyquire( './../dist/main.js', { |
56 |
| -'./float32array.js': Mock, |
57 |
| -'@stdlib/assert-is-float32array': isArray |
58 |
| -}); |
59 |
| -t.strictEqual( mocked(), true, 'detection result is `true` (mocked)' ); |
60 |
| - |
61 |
| -t.end(); |
62 |
| - |
63 |
| -function isArray() { |
64 |
| -return true; |
65 |
| -} |
66 |
| - |
67 |
| -function Mock() { |
68 |
| -return [ |
69 |
| -1.0, |
70 |
| -3.140000104904175, |
71 |
| --3.140000104904175, |
72 |
| -Number.POSITIVE_INFINITY |
73 |
| -]; |
74 |
| -} |
75 |
| -}); |
76 |
| - |
77 |
| -tape( 'if `Float32Array` is not supported, detection result is `false`', function test( t ) { |
78 |
| -var mocked; |
79 |
| -if ( hasFloat32Array ) { |
80 |
| -t.strictEqual( detect(), true, 'detection result is `true`' ); |
81 |
| -} else { |
82 |
| -t.strictEqual( detect(), false, 'detection result is `false`' ); |
83 |
| -} |
84 |
| -mocked = proxyquire( './../dist/main.js', { |
85 |
| -'./float32array.js': {} |
86 |
| -}); |
87 |
| -t.strictEqual( mocked(), false, 'detection result is `false`' ); |
88 |
| - |
89 |
| -mocked = proxyquire( './../dist/main.js', { |
90 |
| -'./float32array.js': Mock1 |
91 |
| -}); |
92 |
| -t.strictEqual( mocked(), false, 'detection result is `false`' ); |
93 |
| - |
94 |
| -mocked = proxyquire( './../dist/main.js', { |
95 |
| -'./float32array.js': Mock2, |
96 |
| -'@stdlib/assert-is-float32array': isArray |
97 |
| -}); |
98 |
| -t.strictEqual( mocked(), false, 'detection result is `false`' ); |
99 |
| - |
100 |
| -mocked = proxyquire( './../dist/main.js', { |
101 |
| -'./float32array.js': Mock3, |
102 |
| -'@stdlib/assert-is-float32array': isArray |
103 |
| -}); |
104 |
| -t.strictEqual( mocked(), false, 'detection result is `false`' ); |
105 |
| - |
106 |
| -mocked = proxyquire( './../dist/main.js', { |
107 |
| -'./float32array.js': Mock4 |
108 |
| -}); |
109 |
| -t.strictEqual( mocked(), false, 'detection result is `false`' ); |
110 |
| - |
111 |
| -t.end(); |
112 |
| - |
113 |
| -function isArray() { |
114 |
| -return true; |
115 |
| -} |
116 |
| - |
117 |
| -function Mock1() { |
118 |
| -// Not a typed array: |
119 |
| -return []; |
120 |
| -} |
121 |
| - |
122 |
| -function Mock2() { |
123 |
| -// Does not lose precision... |
124 |
| -return [ 1.0, 3.14, -3.14, Number.POSITIVE_INFINITY ]; |
125 |
| -} |
126 |
| - |
127 |
| -function Mock3() { |
128 |
| -// Does not overflow... |
129 |
| -return [ 1.0, 3.140000104904175, -3.140000104904175, 5.0e40 ]; |
130 |
| -} |
131 |
| - |
132 |
| -function Mock4() { |
133 |
| -throw new Error( 'beep' ); |
134 |
| -} |
135 |
| -}); |
0 commit comments