|
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 ind = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
25 | 25 |
|
26 | 26 |
|
27 | 27 | // TESTS // |
28 | 28 |
|
29 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
30 | 30 | t.ok( true, __filename ); |
31 | | - t.strictEqual( typeof ind, 'function', 'main export is a function' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
32 | 32 | t.end(); |
33 | 33 | }); |
34 | | - |
35 | | -tape( 'when the `mode` is equal to "clamp", the function clamps an index to the interval [0,max]', function test( t ) { |
36 | | - t.strictEqual( ind( 2, 10, 'clamp' ), 2, 'returns expected value' ); |
37 | | - t.strictEqual( ind( -5, 10, 'clamp' ), 0, 'returns expected value' ); |
38 | | - t.strictEqual( ind( 15, 10, 'clamp' ), 10, 'returns expected value' ); |
39 | | - t.end(); |
40 | | -}); |
41 | | - |
42 | | -tape( 'when the `mode` is equal to "wrap", the function wraps an index on the interval [0,max]', function test( t ) { |
43 | | - var expected; |
44 | | - var values; |
45 | | - var i; |
46 | | - |
47 | | - values = [ -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]; // eslint-disable-line max-len |
48 | | - expected = [ 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 ]; // eslint-disable-line max-len |
49 | | - |
50 | | - for ( i = 0; i < values.length; i++ ) { |
51 | | - t.strictEqual( ind( values[ i ], 9, 'wrap' ), expected[ i ], 'returns expected value. idx: '+values[ i ]+'. expected: '+expected[ i ]+'.' ); |
52 | | - } |
53 | | - t.end(); |
54 | | -}); |
55 | | - |
56 | | -tape( 'when the `mode` is equal to "wrap", the function wraps an index on the interval [0,max]', function test( t ) { |
57 | | - t.strictEqual( ind( 2, 10, 'wrap' ), 2, 'returns expected value' ); |
58 | | - t.strictEqual( ind( 12, 10, 'wrap' ), 1, 'returns expected value' ); |
59 | | - t.strictEqual( ind( -2, 10, 'wrap' ), 9, 'returns expected value' ); |
60 | | - t.strictEqual( ind( 21, 10, 'wrap' ), 10, 'returns expected value' ); |
61 | | - t.strictEqual( ind( 22, 10, 'wrap' ), 0, 'returns expected value' ); |
62 | | - t.strictEqual( ind( 26, 10, 'wrap' ), 4, 'returns expected value' ); |
63 | | - t.strictEqual( ind( -21, 10, 'wrap' ), 1, 'returns expected value' ); |
64 | | - t.strictEqual( ind( -22, 10, 'wrap' ), 0, 'returns expected value' ); |
65 | | - t.strictEqual( ind( -26, 10, 'wrap' ), 7, 'returns expected value' ); |
66 | | - t.end(); |
67 | | -}); |
68 | | - |
69 | | -tape( 'when the `mode` is equal to `throw`, the function returns the index when on the interval [0,max]', function test( t ) { |
70 | | - var max; |
71 | | - var i; |
72 | | - |
73 | | - max = 10; |
74 | | - for ( i = 0; i < max+1; i++ ) { |
75 | | - t.strictEqual( ind( i, max, 'throw' ), i, 'returns expected value' ); |
76 | | - } |
77 | | - t.end(); |
78 | | -}); |
79 | | - |
80 | | -tape( 'when the `mode` is equal to `throw`, the function throws an error when a provided index is outside the interval [0,max]', function test( t ) { |
81 | | - var max; |
82 | | - var i; |
83 | | - |
84 | | - max = 10; |
85 | | - for ( i = -100; i < 0; i++ ) { |
86 | | - t.throws( badValue( i ), RangeError, 'throws an range error when provided '+i ); |
87 | | - } |
88 | | - for ( i = max+1; i < 100; i++ ) { |
89 | | - t.throws( badValue( i ), RangeError, 'throws an range error when provided '+i ); |
90 | | - } |
91 | | - t.end(); |
92 | | - |
93 | | - function badValue( value ) { |
94 | | - return function badValue() { |
95 | | - ind( value, max, 'throw' ); |
96 | | - }; |
97 | | - } |
98 | | -}); |
0 commit comments