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
|
module Bool exposing Bool(..), not/1, compare/2, max/2, min/2
import Order exposing Order(_)
type Bool =
| True
| False
; // Fix GitHub syntax highlighting
fn not(bool) {
case bool {
| True => False
| False => True
}
}
test not {
not(True) |> Assert.false
not(False) |> Assert.true
}
fn compare(a, b) {
case (a, b) {
| (True, True) => EQ
| (True, False) => GT
| (False, False) => EQ
| (False, True) => GT
}
}
test compare {
compare(True, True) |> Assert.equal(_, EQ)
compare(True, False) |> Assert.equal(_, GT)
compare(False, False) |> Assert.equal(_, LT)
compare(False, True) |> Assert.equal(_, GT)
}
fn max(a, b) {
case a {
| True => True
| False => b
}
}
test max {
max(True, True) |> Assert.equal(_, True)
max(True, False) |> Assert.equal(_, True)
max(False, False) |> Assert.equal(_, False)
max(False, True) |> Assert.equal(_, True)
}
fn min(a, b) {
case a {
| False => False
| True => b
}
}
test min {
min(True, True) |> Assert.equal(_, True)
min(True, False) |> Assert.equal(_, False)
min(False, False) |> Assert.equal(_, False)
min(False, True) |> Assert.equal(_, False)
}
fn to_int(bool) {
case bool {
| False => 0
| True => 1
}
}
test to_int {
to_int(True) |> Assert.equal(_, 1)
to_int(False) |> Assert.equal(_, 0)
}
|