name:
tests/Utilities/FilterTest.ts
-rw-r--r--
2287
1import {
2 catchAndAssertEquals,
3 assertArrayEquals,
4 test
5} from "../Utils/Asserts";
6import {
7 Filter
8} from "../../src/Utilities/Filter";
9import {REF_ERROR} from "../../src/Errors";
10
11test("Filter.flatten", function () {
12 assertArrayEquals(Filter.flatten([0, 1, 2, 3, [4, 5], [], [[]], [[[6]]], 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
13 assertArrayEquals(Filter.flatten([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
14 assertArrayEquals(Filter.flatten([0, 1, 2, 3, 4, 5, 6, undefined]), [0, 1, 2, 3, 4, 5, 6, undefined]);
15});
16
17
18test("Filter.filterOutNonNumberValues", function () {
19 assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined]);
20 assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
21});
22
23
24test("Filter.filterOutStringValues", function () {
25 assertArrayEquals(Filter.filterOutStringValues([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined]);
26 assertArrayEquals(Filter.filterOutStringValues([0, 1, 2, 3, "0", "dsadas"]), [0, 1, 2, 3]);
27 assertArrayEquals(Filter.filterOutStringValues(["M", "0", "dsadas"]), []);
28 assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
29});
30
31
32test("Filter.flattenAndThrow", function () {
33 assertArrayEquals(Filter.flattenAndThrow([0, 1, 2, 3, [4, 5], [6], [[7]], [[[8]]], 9]), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
34 assertArrayEquals(Filter.flattenAndThrow([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
35 assertArrayEquals(Filter.flattenAndThrow([0, 1, 2, 3, 4, 5, 6, undefined]), [0, 1, 2, 3, 4, 5, 6, undefined]);
36 catchAndAssertEquals(function () {
37 Filter.flattenAndThrow([0, 1, 2, 3, [4, 5], [], [[]], [[[6]]], 7]);
38 }, REF_ERROR);
39 catchAndAssertEquals(function () {
40 Filter.flattenAndThrow([[]])
41 }, REF_ERROR);
42});
43
44
45test("Filter.stringValuesToZeros", function () {
46 assertArrayEquals(Filter.stringValuesToZeros([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined, 0]);
47 assertArrayEquals(Filter.stringValuesToZeros([0, 1, 2, 3, "0", "dsadas"]), [0, 1, 2, 3, 0, 0]);
48 assertArrayEquals(Filter.stringValuesToZeros(["M", "0", "dsadas"]), [0, 0, 0]);
49 assertArrayEquals(Filter.stringValuesToZeros([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
50});
51
52