forked from etnz/boolgebra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
primary_test.go
101 lines (84 loc) · 1.79 KB
/
primary_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package boolgebra
import (
"fmt"
"testing"
)
func ExampleID() {
A := ID("A")
fmt.Println(A)
//Output: "A"
}
// TesLit ensure that the basic true and false are working accordingly with Is(bool)
func TestLit(t *testing.T) {
if !Lit(true).Is(true) {
t.Error("Lit(true).Is(true) must be true")
}
if !Lit(false).Is(false) {
t.Error("Lit(false).Is(false) must be true")
}
}
func ExampleLit() {
A := Lit(true)
fmt.Println(A)
B := Lit(false)
fmt.Println(B)
//Output:
// Lit(true)
// Lit(false)
}
func ExampleNot() {
fmt.Println(Not(ID("A")))
fmt.Println(Not(Lit(true)))
fmt.Println(Not(Lit(false)))
//Output:
// Not("A")
// Lit(false)
// Lit(true)
}
func ExampleAnd() {
A := ID("A")
B := ID("B")
C := ID("C")
fmt.Println(And(A, Lit(true)))
fmt.Println(And(A, Lit(false)))
fmt.Println(And(A, B, C))
fmt.Println(And(A, Not(B)))
//Output:
// "A"
// Lit(false)
// And("A", "B", "C")
// And("A", Not("B"))
}
func ExampleOr() {
A := ID("A")
B := ID("B")
fmt.Println(Or(A, Lit(true)))
fmt.Println(Or(A, Lit(false)))
fmt.Println(Or(A, Not(B)))
//Output:
// Lit(true)
// "A"
// Or("A", Not("B"))
}
func truthTester(t *testing.T, label string, z Expr, expected bool) {
if !z.Is(expected) {
t.Errorf("%s: expected %v got %v", label, expected, z)
}
}
func Test_truthTables(t *testing.T) {
T := Lit(true)
F := Lit(false)
//Not
truthTester(t, "Not(F)", Not(F), true)
truthTester(t, "Not(T)", Not(T), false)
//Or
truthTester(t, "Or(F,F)", Or(F, F), false)
truthTester(t, "Or(F,T)", Or(F, T), true)
truthTester(t, "Or(T,F)", Or(T, F), true)
truthTester(t, "Or(T,T)", Or(T, T), true)
//And
truthTester(t, "And(F,F)", And(F, F), false)
truthTester(t, "And(F,T)", And(F, T), false)
truthTester(t, "And(T,F)", And(T, F), false)
truthTester(t, "And(T,T)", And(T, T), true)
}