kibana/packages/kbn-tinymath/test/functions/add.test.js
Wylie Conlon ac39321fc5
Tinymath is now a Kibana package (#89383)
* Tinymath is now a Kibana package

* Rename to @kbn/tinymath

* Update import style

* Update README

* Use commonjs import syntax

* Fix to commonjs export

* More commonjs fixes
2021-01-28 13:58:37 -05:00

33 lines
1.2 KiB
JavaScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/
const { add } = require('../../src/functions/add.js');
describe('Add', () => {
it('numbers', () => {
expect(add(1)).toEqual(1);
expect(add(10, 2, 5, 8)).toEqual(25);
expect(add(0.1, 0.2, 0.4, 0.3)).toEqual(0.1 + 0.2 + 0.3 + 0.4);
});
it('arrays & numbers', () => {
expect(add([10, 20, 30, 40], 10, 20, 30)).toEqual([70, 80, 90, 100]);
expect(add(10, [10, 20, 30, 40], [1, 2, 3, 4], 22)).toEqual([43, 54, 65, 76]);
});
it('arrays', () => {
expect(add([1, 2, 3, 4])).toEqual(10);
expect(add([1, 2, 3, 4], [1, 2, 5, 10])).toEqual([2, 4, 8, 14]);
expect(add([1, 2, 3, 4], [1, 2, 5, 10], [10, 20, 30, 40])).toEqual([12, 24, 38, 54]);
expect(add([11, 48, 60, 72], [1, 2, 3, 4])).toEqual([12, 50, 63, 76]);
});
it('array length mismatch', () => {
expect(() => add([1, 2], [3])).toThrow('Array length mismatch');
});
});