name:
src/test/js/formulas/math/RANDBETWEENTest.ts
-rw-r--r--
1178
1import { assert } from "chai";
2import { it, describe } from "../../testutils/TestUtils";
3import { F7ExceptionName } from "../../../../main/js/errors/F7ExceptionName";
4import { NAException } from "../../../../main/js/errors/NAException";
5import { RANDBETWEEN } from "../../../../main/js/formulas/math/RANDBETWEEN";
6import { Converters } from "../../../../main/js/utils/Converters";
7
8describe("RANDBETWEEN", function () {
9 it("should return random number between X and Y", function () {
10 for (let i = 0; i < 1000; i++) {
11 const result = Converters.castAsNumber(RANDBETWEEN.SELF.run(null, 1, 10));
12 assert.isAtLeast(result, 1);
13 assert.isAtMost(result, 10);
14 }
15 });
16
17 it("should return an error when the low is greater than the high", function () {
18 assert.deepEqual((RANDBETWEEN.SELF.run(null, 10, 1) as NAException).name, F7ExceptionName.NUM);
19 });
20
21 it("should return error when argument lengths are wrong", function () {
22 assert.deepEqual((RANDBETWEEN.SELF.run(null) as NAException).name, F7ExceptionName.NA);
23 assert.deepEqual(
24 (RANDBETWEEN.SELF.run(null, "A", "B", "C") as NAException).name,
25 F7ExceptionName.NA
26 );
27 });
28});