summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/core
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2019-04-23 15:05:27 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2019-08-02 18:34:18 +0000
commit5894df57d34c8d9d41db9bf901502d42dac9d884 (patch)
treeef999088a48b8b0f2f846c84f304939cdccaea1a /addons/web/static/tests/core
parente488f208d21b7cff86d22ac12e894d953ad65943 (diff)
[IMP] web: add math_utils to core
math_utils is a small library that exports two functions: - cartesian: allows to compute the cartesian products of any numbers of arrays while preserving the internal structures of their elements. - sections: returns an array with all the initial sections of the array passed as parameter.
Diffstat (limited to 'addons/web/static/tests/core')
-rw-r--r--addons/web/static/tests/core/math_utils_tests.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/addons/web/static/tests/core/math_utils_tests.js b/addons/web/static/tests/core/math_utils_tests.js
new file mode 100644
index 00000000000..894cb0be4f7
--- /dev/null
+++ b/addons/web/static/tests/core/math_utils_tests.js
@@ -0,0 +1,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]]);
+ });
+
+});
+}); \ No newline at end of file