1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
odoo.define('web.math_utils_tests', function(require) {
"use strict";
var mathUtils = require('web.mathUtils');
var cartesian = mathUtils.cartesian;
QUnit.module('mathUtils', function () {
QUnit.module('cartesian');
QUnit.test('cartesian product of zero arrays', function(assert) {
assert.expect(1);
assert.deepEqual(cartesian(), [undefined],
"the unit of the product is a singleton");
});
QUnit.test('cartesian product of a single array', function(assert) {
assert.expect(5);
assert.deepEqual(cartesian([]), []);
assert.deepEqual(cartesian([1]), [1],
"we don't want unecessary brackets");
assert.deepEqual(cartesian([1, 2]), [1, 2]);
assert.deepEqual(cartesian([[1, 2]]), [[1, 2]],
"the internal structure of elements should be preserved");
assert.deepEqual(cartesian([[1, 2], [3, [2]]]), [[1, 2], [3, [2]]],
"the internal structure of elements should be preserved");
});
QUnit.test('cartesian product of two arrays', function(assert) {
assert.expect(5);
assert.deepEqual(cartesian([], []), []);
assert.deepEqual(cartesian([1], []), []);
assert.deepEqual(cartesian([1], [2]), [[1, 2]]);
assert.deepEqual(cartesian([1, 2], [3]), [[1, 3], [2, 3]]);
assert.deepEqual(cartesian([[1], 4], [2, [3]]), [[[1], 2], [[1], [3]], [4, 2], [4, [3]] ],
"the internal structure of elements should be preserved");
});
QUnit.test('cartesian product of three arrays', function(assert) {
assert.expect(4);
assert.deepEqual(cartesian([], [], []), []);
assert.deepEqual(cartesian([1], [], [2, 5]), []);
assert.deepEqual(cartesian([1], [2], [3]), [[1, 2, 3]],
"we should have no unecessary brackets, we want elements to be 'triples'");
assert.deepEqual(cartesian([[1], 2], [3], [4]), [[[1], 3, 4], [2, 3, 4]],
"the internal structure of elements should be preserved");
});
QUnit.test('cartesian product of four arrays', function(assert) {
assert.expect(1);
assert.deepEqual(cartesian([1], [2], [3], [4]), [[1, 2, 3, 4]]);
});
});
});
|