16
16
* limitations under the License.
17
17
*/
18
18
19
+ /* eslint-disable max-len */
20
+
19
21
'use strict' ;
20
22
21
23
// MODULES //
22
24
23
25
var tape = require ( 'tape' ) ;
26
+ var toAccessorArray = require ( '@stdlib/array/base/to-accessor-array' ) ;
24
27
var cartesianProduct = require ( './../lib' ) ;
25
28
26
29
@@ -32,7 +35,7 @@ tape( 'main export is a function', function test( t ) {
32
35
t . end ( ) ;
33
36
} ) ;
34
37
35
- tape ( 'the function returns the Cartesian product' , function test ( t ) {
38
+ tape ( 'the function returns the Cartesian product (indexed) ' , function test ( t ) {
36
39
var expected ;
37
40
var actual ;
38
41
@@ -55,7 +58,30 @@ tape( 'the function returns the Cartesian product', function test( t ) {
55
58
t . end ( ) ;
56
59
} ) ;
57
60
58
- tape ( 'the function returns an empty array if provided one or more empty arrays' , function test ( t ) {
61
+ tape ( 'the function returns the Cartesian product (accessors)' , function test ( t ) {
62
+ var expected ;
63
+ var actual ;
64
+
65
+ actual = cartesianProduct ( toAccessorArray ( [ 1 , 2 ] ) , toAccessorArray ( [ 3 , 4 ] ) ) ;
66
+ expected = [ [ 1 , 3 ] , [ 1 , 4 ] , [ 2 , 3 ] , [ 2 , 4 ] ] ;
67
+ t . deepEqual ( actual , expected , 'returns expected value' ) ;
68
+
69
+ actual = cartesianProduct ( toAccessorArray ( [ 1 ] ) , toAccessorArray ( [ 3 , 4 ] ) ) ;
70
+ expected = [ [ 1 , 3 ] , [ 1 , 4 ] ] ;
71
+ t . deepEqual ( actual , expected , 'returns expected value' ) ;
72
+
73
+ actual = cartesianProduct ( toAccessorArray ( [ 1 , 2 ] ) , toAccessorArray ( [ 3 ] ) ) ;
74
+ expected = [ [ 1 , 3 ] , [ 2 , 3 ] ] ;
75
+ t . deepEqual ( actual , expected , 'returns expected value' ) ;
76
+
77
+ actual = cartesianProduct ( toAccessorArray ( [ 1 , 2 ] ) , toAccessorArray ( [ 3 , 4 , 5 ] ) ) ;
78
+ expected = [ [ 1 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 2 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] ] ;
79
+ t . deepEqual ( actual , expected , 'returns expected value' ) ;
80
+
81
+ t . end ( ) ;
82
+ } ) ;
83
+
84
+ tape ( 'the function returns an empty array if provided one or more empty arrays (indexed)' , function test ( t ) {
59
85
var actual ;
60
86
61
87
actual = cartesianProduct ( [ ] , [ ] ) ;
@@ -69,3 +95,18 @@ tape( 'the function returns an empty array if provided one or more empty arrays'
69
95
70
96
t . end ( ) ;
71
97
} ) ;
98
+
99
+ tape ( 'the function returns an empty array if provided one or more empty arrays (accessors)' , function test ( t ) {
100
+ var actual ;
101
+
102
+ actual = cartesianProduct ( toAccessorArray ( [ ] ) , toAccessorArray ( [ ] ) ) ;
103
+ t . deepEqual ( actual , [ ] , 'returns expected value' ) ;
104
+
105
+ actual = cartesianProduct ( toAccessorArray ( [ 1 , 2 ] ) , toAccessorArray ( [ ] ) ) ;
106
+ t . deepEqual ( actual , [ ] , 'returns expected value' ) ;
107
+
108
+ actual = cartesianProduct ( toAccessorArray ( [ ] ) , toAccessorArray ( [ 3 , 4 ] ) ) ;
109
+ t . deepEqual ( actual , [ ] , 'returns expected value' ) ;
110
+
111
+ t . end ( ) ;
112
+ } ) ;
0 commit comments