Skip to content

Commit 12ca9ae

Browse files
test: add tests for random/tools/unary
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7899877 commit 12ca9ae

1 file changed

Lines changed: 312 additions & 1 deletion

File tree

  • lib/node_modules/@stdlib/random/tools/unary/test

lib/node_modules/@stdlib/random/tools/unary/test/test.js

Lines changed: 312 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var exponential = require( '@stdlib/random/base/exponential' );
25+
var dtypes = require( '@stdlib/ndarray/dtypes' );
2426
var Random = require( './../lib' );
2527

2628

@@ -32,4 +34,313 @@ tape( 'main export is a function', function test( t ) {
3234
t.end();
3335
});
3436

35-
// FIXME: add tests
37+
tape( 'the function throws an error if the first argument is not a function', function test( t ) {
38+
var values;
39+
var idt;
40+
var odt;
41+
var i;
42+
43+
idt = dtypes( 'real_and_generic' );
44+
odt = dtypes( 'real_floating_point_and_generic' );
45+
46+
values = [
47+
'5',
48+
5,
49+
NaN,
50+
true,
51+
false,
52+
null,
53+
void 0,
54+
[],
55+
{}
56+
];
57+
58+
for ( i = 0; i < values.length; i++ ) {
59+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
60+
}
61+
t.end();
62+
63+
function badValue( value ) {
64+
return function badValue() {
65+
return new Random( value, idt, odt, {
66+
'output': 'real_floating_point_and_generic'
67+
});
68+
};
69+
}
70+
});
71+
72+
tape( 'the function throws an error if the second argument is not an array of data types', function test( t ) {
73+
var values;
74+
var odt;
75+
var i;
76+
77+
odt = dtypes( 'real_floating_point_and_generic' );
78+
79+
values = [
80+
'5',
81+
5,
82+
NaN,
83+
true,
84+
false,
85+
null,
86+
void 0,
87+
{},
88+
[],
89+
[ 'foo' ],
90+
[ 1, 2, 3 ],
91+
[ 'float64', 1 ],
92+
exponential
93+
];
94+
95+
for ( i = 0; i < values.length; i++ ) {
96+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
97+
}
98+
t.end();
99+
100+
function badValue( value ) {
101+
return function badValue() {
102+
return new Random( exponential, value, odt, {
103+
'output': 'real_floating_point_and_generic'
104+
});
105+
};
106+
}
107+
});
108+
109+
tape( 'the function throws an error if the third argument is not an array of data types', function test( t ) {
110+
var values;
111+
var idt;
112+
var i;
113+
114+
idt = dtypes( 'real_and_generic' );
115+
116+
values = [
117+
'5',
118+
5,
119+
NaN,
120+
true,
121+
false,
122+
null,
123+
void 0,
124+
{},
125+
[],
126+
[ 'foo' ],
127+
[ 1, 2, 3 ],
128+
[ 'float64', 1 ],
129+
exponential
130+
];
131+
132+
for ( i = 0; i < values.length; i++ ) {
133+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
134+
}
135+
t.end();
136+
137+
function badValue( value ) {
138+
return function badValue() {
139+
return new Random( exponential, idt, value, {
140+
'output': 'real_floating_point_and_generic'
141+
});
142+
};
143+
}
144+
});
145+
146+
tape( 'the function throws an error if the fourth argument is not an object', function test( t ) {
147+
var values;
148+
var idt;
149+
var odt;
150+
var i;
151+
152+
idt = dtypes( 'real_and_generic' );
153+
odt = dtypes( 'real_floating_point_and_generic' );
154+
155+
values = [
156+
'5',
157+
5,
158+
NaN,
159+
true,
160+
false,
161+
null,
162+
void 0,
163+
[],
164+
exponential
165+
];
166+
167+
for ( i = 0; i < values.length; i++ ) {
168+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
169+
}
170+
t.end();
171+
172+
function badValue( value ) {
173+
return function badValue() {
174+
return new Random( exponential, idt, odt, value );
175+
};
176+
}
177+
});
178+
179+
tape( 'the function throws an error if the fourth argument does not have a valid output data type policy', function test( t ) {
180+
var values;
181+
var idt;
182+
var odt;
183+
var i;
184+
185+
idt = dtypes( 'real_and_generic' );
186+
odt = dtypes( 'real_floating_point_and_generic' );
187+
188+
values = [
189+
'foo',
190+
5,
191+
NaN,
192+
true,
193+
false,
194+
null,
195+
void 0,
196+
[],
197+
{},
198+
exponential
199+
];
200+
201+
for ( i = 0; i < values.length; i++ ) {
202+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
203+
}
204+
t.end();
205+
206+
function badValue( value ) {
207+
return function badValue() {
208+
return new Random( exponential, idt, odt, {
209+
'output': value
210+
});
211+
};
212+
}
213+
});
214+
215+
tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) {
216+
var values;
217+
var idt;
218+
var odt;
219+
var i;
220+
221+
idt = dtypes( 'real_and_generic' );
222+
odt = dtypes( 'real_floating_point_and_generic' );
223+
224+
values = [
225+
'5',
226+
5,
227+
NaN,
228+
true,
229+
false,
230+
null,
231+
void 0,
232+
[],
233+
exponential
234+
];
235+
236+
for ( i = 0; i < values.length; i++ ) {
237+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
238+
}
239+
t.end();
240+
241+
function badValue( value ) {
242+
return function badValue() {
243+
return new Random( exponential, idt, odt, {
244+
'output': 'real_floating_point_and_generic'
245+
}, value );
246+
};
247+
}
248+
});
249+
250+
tape( 'the function throws an error if provided an invalid `order` option', function test( t ) {
251+
var values;
252+
var idt;
253+
var odt;
254+
var i;
255+
256+
idt = dtypes( 'real_and_generic' );
257+
odt = dtypes( 'real_floating_point_and_generic' );
258+
259+
values = [
260+
'foo',
261+
5,
262+
NaN,
263+
true,
264+
false,
265+
null,
266+
void 0,
267+
[],
268+
{},
269+
exponential
270+
];
271+
272+
for ( i = 0; i < values.length; i++ ) {
273+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
274+
}
275+
t.end();
276+
277+
function badValue( value ) {
278+
return function badValue() {
279+
return new Random( exponential, idt, odt, {
280+
'output': 'real_floating_point_and_generic'
281+
}, {
282+
'order': value
283+
});
284+
};
285+
}
286+
});
287+
288+
tape( 'the function returns an instance', function test( t ) {
289+
var idt;
290+
var odt;
291+
var r;
292+
293+
idt = dtypes( 'real_and_generic' );
294+
odt = dtypes( 'real_floating_point_and_generic' );
295+
296+
r = new Random( exponential, idt, odt, {
297+
'output': 'real_floating_point_and_generic'
298+
});
299+
t.strictEqual( r instanceof Random, true, 'returns an instance' );
300+
t.end();
301+
});
302+
303+
tape( 'the function returns an instance (w/o new)', function test( t ) {
304+
var idt;
305+
var odt;
306+
var r;
307+
308+
idt = dtypes( 'real_and_generic' );
309+
odt = dtypes( 'real_floating_point_and_generic' );
310+
311+
r = Random( exponential, idt, odt, { // eslint-disable-line new-cap
312+
'output': 'real_floating_point_and_generic'
313+
});
314+
t.strictEqual( r instanceof Random, true, 'returns an instance' );
315+
t.end();
316+
});
317+
318+
tape( 'the instance has a `generate` method', function test( t ) {
319+
var idt;
320+
var odt;
321+
var r;
322+
323+
idt = dtypes( 'real_and_generic' );
324+
odt = dtypes( 'real_floating_point_and_generic' );
325+
326+
r = new Random( exponential, idt, odt, {
327+
'output': 'real_floating_point_and_generic'
328+
});
329+
t.strictEqual( typeof r.generate, 'function', 'has a generate method' );
330+
t.end();
331+
});
332+
333+
tape( 'the instance has an `assign` method', function test( t ) {
334+
var idt;
335+
var odt;
336+
var r;
337+
338+
idt = dtypes( 'real_and_generic' );
339+
odt = dtypes( 'real_floating_point_and_generic' );
340+
341+
r = new Random( exponential, idt, odt, {
342+
'output': 'real_floating_point_and_generic'
343+
});
344+
t.strictEqual( typeof r.assign, 'function', 'has an assign method' );
345+
t.end();
346+
});

0 commit comments

Comments
 (0)