Skip to content

Commit 6603d5e

Browse files
committed
test: update tests
--- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent b595c37 commit 6603d5e

File tree

1 file changed

+137
-51
lines changed
  • lib/node_modules/@stdlib/dstructs/named-typed-tuple/test

1 file changed

+137
-51
lines changed

lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js

Lines changed: 137 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tape( 'a tuple has a `slice` method', function test( t ) {
4848
t.end();
4949
});
5050

51-
tape( 'the method throws an error if invoked with a `this` context which is not a namedtypedtuple instance', function test( t ) {
51+
tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) {
5252
var values;
5353
var Point;
5454
var p;
@@ -81,6 +81,72 @@ tape( 'the method throws an error if invoked with a `this` context which is not
8181
}
8282
});
8383

84+
tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance (start)', function test( t ) {
85+
var values;
86+
var Point;
87+
var p;
88+
var i;
89+
90+
Point = namedtypedtuple( [ 'x', 'y', 'z' ] );
91+
p = new Point( [ 10, 20, 30 ] );
92+
93+
values = [
94+
'5',
95+
5,
96+
NaN,
97+
true,
98+
false,
99+
null,
100+
void 0,
101+
{},
102+
[],
103+
function noop() {}
104+
];
105+
for ( i = 0; i < values.length; i++ ) {
106+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
107+
}
108+
t.end();
109+
110+
function badValue( value ) {
111+
return function badValue() {
112+
return p.slice.call( value, 0 );
113+
};
114+
}
115+
});
116+
117+
tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance (start, end)', function test( t ) {
118+
var values;
119+
var Point;
120+
var p;
121+
var i;
122+
123+
Point = namedtypedtuple( [ 'x', 'y', 'z' ] );
124+
p = new Point( [ 10, 20, 30 ] );
125+
126+
values = [
127+
'5',
128+
5,
129+
NaN,
130+
true,
131+
false,
132+
null,
133+
void 0,
134+
{},
135+
[],
136+
function noop() {}
137+
];
138+
for ( i = 0; i < values.length; i++ ) {
139+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
140+
}
141+
t.end();
142+
143+
function badValue( value ) {
144+
return function badValue() {
145+
return p.slice.call( value, 0, 1 );
146+
};
147+
}
148+
});
149+
84150
tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) {
85151
var values;
86152
var Point;
@@ -113,6 +179,38 @@ tape( 'the method throws an error if provided a first argument which is not an i
113179
}
114180
});
115181

182+
tape( 'the method throws an error if provided a first argument which is not an integer (end)', function test( t ) {
183+
var values;
184+
var Point;
185+
var p;
186+
var i;
187+
188+
Point = namedtypedtuple( [ 'x', 'y', 'z' ] );
189+
p = new Point( [ 10, 20, 30 ] );
190+
191+
values = [
192+
'5',
193+
3.14,
194+
NaN,
195+
true,
196+
false,
197+
null,
198+
void 0,
199+
{},
200+
[]
201+
];
202+
for ( i = 0; i < values.length; i++ ) {
203+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
204+
}
205+
t.end();
206+
207+
function badValue( value ) {
208+
return function badValue() {
209+
return p.slice( value, 1 );
210+
};
211+
}
212+
});
213+
116214
tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) {
117215
var values;
118216
var Point;
@@ -153,42 +251,41 @@ tape( 'if called without arguments, the method returns a tuple containing the sa
153251

154252
Point = namedtypedtuple( [ 'x', 'y', 'z' ] );
155253
p = new Point( [ 10, 20, 30 ] );
254+
156255
expected = {
157256
'x': 10,
158257
'y': 20,
159258
'z': 30
160259
};
161260
actual = p.slice();
162-
163-
t.deepEqual({
261+
actual = {
164262
'x': actual.x,
165263
'y': actual.y,
166264
'z': actual.z
167-
}, expected, 'returns expected value' );
168-
t.notEqual( actual, p, 'returns a new instance' );
265+
};
266+
267+
t.notEqual( actual, p, 'returns expected value' );
268+
t.strictEqual( actual instanceof Point, true, 'returns expected value' );
269+
t.deepEqual( actual, expected, 'returns expected value' );
169270
t.end();
170271
});
171272

172-
tape( 'if called with one argument, the method returns a tuple containing elements starting from a specified beginning index (inclusive)', function test( t ) {
273+
tape( 'if provided one argument, the method returns a tuple containing elements starting from a specified index (inclusive)', function test( t ) {
173274
var expected;
174275
var actual;
175276
var Point;
176277
var p;
177278

178279
Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] );
179280
p = new Point( [ 1, 2, 3, 4 ] );
180-
expected = {
181-
'y': 2,
182-
'z': 3,
183-
'w': 4
184-
};
281+
282+
expected = [ 2, 3, 4 ];
185283
actual = p.slice( 1 );
186284

187-
t.deepEqual({
188-
'y': actual.y,
189-
'z': actual.z,
190-
'w': actual.w
191-
}, expected, 'returns expected value' );
285+
t.notEqual( actual, p, 'returns expected value' );
286+
t.strictEqual( actual instanceof Point, true, 'returns expected value' );
287+
t.deepEqual( actual, expected, 'returns expected value' );
288+
t.deepEqual( actual.fields, [ 'y', 'z', 'w' ], 'returns expected value' );
192289
t.end();
193290
});
194291

@@ -200,33 +297,26 @@ tape( 'if provided two arguments, the method returns a tuple containing elements
200297

201298
Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] );
202299
p = new Point( [ 1, 2, 3, 4 ] );
203-
expected = {
204-
'y': 2,
205-
'z': 3
206-
};
300+
301+
expected = [ 2, 3 ];
207302
actual = p.slice( 1, 3 );
208303

209-
t.deepEqual({
210-
'y': actual.y,
211-
'z': actual.z
212-
}, expected, 'returns expected value' );
304+
t.notEqual( actual, p, 'returns expected value' );
305+
t.strictEqual( actual instanceof Point, true, 'returns expected value' );
306+
t.deepEqual( actual, expected, 'returns expected value' );
307+
t.deepEqual( actual.fields, [ 'y', 'z' ], 'returns expected value' );
213308

214-
expected = {
215-
'y': 2,
216-
'z': 3,
217-
'w': 4
218-
};
309+
expected = [ 2, 3, 4 ];
219310
actual = p.slice( 1, 30 );
220311

221-
t.deepEqual({
222-
'y': actual.y,
223-
'z': actual.z,
224-
'w': actual.w
225-
}, expected, 'returns expected value' );
312+
t.notEqual( actual, p, 'returns expected value' );
313+
t.strictEqual( actual instanceof Point, true, 'returns expected value' );
314+
t.deepEqual( actual, expected, 'returns expected value' );
315+
t.deepEqual( actual.fields, [ 'y', 'z', 'w' ], 'returns expected value' );
226316
t.end();
227317
});
228318

229-
tape( 'the method resolves negative indices relative to the last element', function test( t ) {
319+
tape( 'the method supports negative indices', function test( t ) {
230320
var expected;
231321
var actual;
232322
var Point;
@@ -235,25 +325,21 @@ tape( 'the method resolves negative indices relative to the last element', funct
235325
Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] );
236326
p = new Point( [ 1, 2, 3, 4 ] );
237327

238-
expected = {
239-
'y': 2,
240-
'z': 3
241-
};
328+
expected = [ 2, 3 ];
242329
actual = p.slice( -3, -1 );
243-
t.deepEqual({
244-
'y': actual.y,
245-
'z': actual.z
246-
}, expected, 'returns expected value' );
247330

248-
expected = {
249-
'x': 1,
250-
'y': 2
251-
};
331+
t.notEqual( actual, p, 'returns expected value' );
332+
t.strictEqual( actual instanceof Point, true, 'returns expected value' );
333+
t.deepEqual( actual, expected, 'returns expected value' );
334+
t.deepEqual( actual.fields, [ 'y', 'z' ], 'returns expected value' );
335+
336+
expected = [ 2, 3 ];
252337
actual = p.slice( -30, -2 );
253-
t.deepEqual({
254-
'x': actual.x,
255-
'y': actual.y
256-
}, expected, 'returns expected value' );
338+
339+
t.notEqual( actual, p, 'returns expected value' );
340+
t.strictEqual( actual instanceof Point, true, 'returns expected value' );
341+
t.deepEqual( actual, expected, 'returns expected value' );
342+
t.deepEqual( actual.fields, [ 'y', 'z' ], 'returns expected value' );
257343
t.end();
258344
});
259345

0 commit comments

Comments
 (0)