-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpressionBuilder.test.js
67 lines (57 loc) · 1.89 KB
/
ExpressionBuilder.test.js
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
57
58
59
60
61
62
63
64
65
66
67
const ExpressionBuilder = require("./ExpressionBuilder");
describe("ExpressionBuilder", () => {
const eb = new ExpressionBuilder();
it("finds all of the non-empty subsets of a set (Array)", () => {
expect(eb.nonEmptySubsets(new Set([1]))).toEqual(new Set([[1]]));
});
it("finds all of the non-empty subsets of a set (Array)", () => {
expect(new Set(eb.nonEmptySubsets([1, 2, 3]))).toEqual(
new Set([[1], [2], [3], [1, 2], [2, 3], [1, 3], [1, 2, 3]])
);
});
it("arrayEquals", () => {
expect(eb.arrayEquals([], [])).toEqual(true);
expect(eb.arrayEquals([true, false], [true, false])).toEqual(true);
expect(eb.arrayEquals([true, false], [true, true])).toEqual(false);
expect(eb.arrayEquals([true, true], [true, true, true])).toEqual(false);
});
it("containsAllMinterms", () => {
expect(
eb.containsAllMinterms(
[
{ minterms: [[true, true], [true, false]] },
{ minterms: [[true, true], [false, false]] }
],
[[true, true], [true, false], [false, false]]
)
).toEqual(true);
expect(
eb.containsAllMinterms(
[
{ minterms: [[true, true], [true, false]] },
{ minterms: [[true, true]] }
],
[[true, true], [true, false], [false, false]]
)
).toEqual(false);
});
it("moreConcisePrimeImplicant", () => {
const big = [
{ term: [true, null, null] },
{ term: [true, null, false] },
{ term: [false, null, false] }
];
const small = [
{ term: [true, true, true] },
{ term: [false, false, false] }
];
const smallWithSmallerTerms = [
{ term: [true, true, true] },
{ term: [false, false, null] }
];
expect(eb.moreConcisePrimeImplicantSet(big, small)).toEqual(small);
expect(
eb.moreConcisePrimeImplicantSet(small, smallWithSmallerTerms)
).toEqual(smallWithSmallerTerms);
});
});