|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +'use strict'; |
| 20 | + |
| 21 | +// MODULES // |
| 22 | + |
| 23 | +var tape = require( 'tape' ); |
| 24 | +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); |
| 25 | +var isFunction = require( '@stdlib/assert/is-function' ); |
| 26 | +var Complex128Array = require( './../lib' ); |
| 27 | + |
| 28 | + |
| 29 | +// TESTS // |
| 30 | + |
| 31 | +tape( 'main export is a function', function test( t ) { |
| 32 | + t.ok( true, __filename ); |
| 33 | + t.strictEqual( typeof Complex128Array, 'function', 'main export is a function' ); |
| 34 | + t.end(); |
| 35 | +}); |
| 36 | + |
| 37 | +tape( 'attached to the prototype of the main export is a `toString` method', function test( t ) { |
| 38 | + t.strictEqual( hasOwnProp( Complex128Array.prototype, 'toString' ), true, 'has property' ); |
| 39 | + t.strictEqual( isFunction( Complex128Array.prototype.toString ), true, 'has method' ); |
| 40 | + t.end(); |
| 41 | +}); |
| 42 | + |
| 43 | +tape( 'the method throws an error if invoked with a `this` context which is not a complex number array instance', function test( t ) { |
| 44 | + var values; |
| 45 | + var arr; |
| 46 | + var i; |
| 47 | + |
| 48 | + arr = new Complex128Array( 5 ); |
| 49 | + |
| 50 | + values = [ |
| 51 | + '5', |
| 52 | + 5, |
| 53 | + NaN, |
| 54 | + true, |
| 55 | + false, |
| 56 | + null, |
| 57 | + void 0, |
| 58 | + {}, |
| 59 | + [], |
| 60 | + function noop() {} |
| 61 | + ]; |
| 62 | + for ( i = 0; i < values.length; i++ ) { |
| 63 | + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
| 64 | + } |
| 65 | + t.end(); |
| 66 | + |
| 67 | + function badValue( value ) { |
| 68 | + return function badValue() { |
| 69 | + return arr.toString.call( value ); |
| 70 | + }; |
| 71 | + } |
| 72 | +}); |
| 73 | + |
| 74 | +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { |
| 75 | + var str; |
| 76 | + var arr; |
| 77 | + |
| 78 | + arr = new Complex128Array(); |
| 79 | + str = arr.toString(); |
| 80 | + |
| 81 | + t.strictEqual( str, '', 'returns expected value' ); |
| 82 | + t.end(); |
| 83 | +}); |
| 84 | + |
| 85 | +tape( 'the method returns a string representation of a complex number array', function test( t ) { |
| 86 | + var expected; |
| 87 | + var str; |
| 88 | + var arr; |
| 89 | + |
| 90 | + arr = new Complex128Array( [ 1, 2, -3, -4 ] ); |
| 91 | + expected = '1 + 2i,-3 - 4i'; |
| 92 | + |
| 93 | + str = arr.toString(); |
| 94 | + |
| 95 | + t.strictEqual( str, expected, 'returns expected value' ); |
| 96 | + t.end(); |
| 97 | +}); |
0 commit comments