Skip to content

Commit 2356ab8

Browse files
committed
Add tests
1 parent c14d2ff commit 2356ab8

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

lib/node_modules/@stdlib/array/complex64/test/test.from.js

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,53 @@ tape( 'attached to the main export is a `from` method for creating a complex num
5050
t.end();
5151
});
5252

53+
tape( 'the method throws an error if invoked with `this` context which is not a constructor', function test( t ) {
54+
var values;
55+
var i;
56+
57+
values = [
58+
'5',
59+
5,
60+
NaN,
61+
true,
62+
false,
63+
null,
64+
void 0,
65+
{},
66+
[]
67+
];
68+
for ( i = 0; i < values.length; i++ ) {
69+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
70+
}
71+
t.end();
72+
73+
function badValue( value ) {
74+
return function badValue() {
75+
return Complex64Array.from.call( value, [] );
76+
};
77+
}
78+
});
79+
80+
tape( 'the method throws an error if invoked with `this` context which is not a complex array constructor', function test( t ) {
81+
var values;
82+
var i;
83+
84+
values = [
85+
Complex64,
86+
function noop() {}
87+
];
88+
for ( i = 0; i < values.length; i++ ) {
89+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
90+
}
91+
t.end();
92+
93+
function badValue( value ) {
94+
return function badValue() {
95+
return Complex64Array.from.call( value, [] );
96+
};
97+
}
98+
});
99+
53100
tape( 'the method throws an error if not provided an iterable or array-like object', function test( t ) {
54101
var values;
55102
var i;
@@ -130,7 +177,7 @@ tape( 'the method throws an error if not provided an iterable or array-like obje
130177

131178
function badValue( value ) {
132179
return function badValue() {
133-
return Complex64Array.from( value, clbk, Complex64Array );
180+
return Complex64Array.from( value, clbk, {} );
134181
};
135182
}
136183

@@ -139,6 +186,60 @@ tape( 'the method throws an error if not provided an iterable or array-like obje
139186
}
140187
});
141188

189+
tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) {
190+
var values;
191+
var i;
192+
193+
values = [
194+
'5',
195+
5,
196+
NaN,
197+
true,
198+
false,
199+
null,
200+
void 0,
201+
{},
202+
[]
203+
];
204+
for ( i = 0; i < values.length; i++ ) {
205+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
206+
}
207+
t.end();
208+
209+
function badValue( value ) {
210+
return function badValue() {
211+
return Complex64Array.from( [], value );
212+
};
213+
}
214+
});
215+
216+
tape( 'the method throws an error if provided a second argument which is not a function (thisArg)', function test( t ) {
217+
var values;
218+
var i;
219+
220+
values = [
221+
'5',
222+
5,
223+
NaN,
224+
true,
225+
false,
226+
null,
227+
void 0,
228+
{},
229+
[]
230+
];
231+
for ( i = 0; i < values.length; i++ ) {
232+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
233+
}
234+
t.end();
235+
236+
function badValue( value ) {
237+
return function badValue() {
238+
return Complex64Array.from( [], value, {} );
239+
};
240+
}
241+
});
242+
142243
tape( 'the method returns a complex number array', function test( t ) {
143244
var arr;
144245
var z;

0 commit comments

Comments
 (0)