-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathabout_numbers_and_booleans.exs
executable file
·65 lines (53 loc) · 1.49 KB
/
about_numbers_and_booleans.exs
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
defmodule AboutNumbersAndBooleans do
use Koans
think "Basics numbers types" do
assert_? is_integer(42)
assert_? is_integer(42.0)
assert_? is_float(42.0)
assert_? is_float(42)
end
think "Is a hexadecimal number an integer?" do
assert_? is_integer(0x2A)
end
think "Answer to the Ultimate Question of Life, the Universe, and Everything" do
a_hex = 0x20
a_dec = 10
assert a_hex + a_dec == __?
end
think "You can use _ as separator in integer" do
assert 100_000_000 == __?
end
think "Integers and floats have value equality" do
assert_? 4 == 4.0
end
think "Integers and floats have value inequality" do
assert_? 4 != 2.0
end
think "Strict equality checks types" do
assert_? 4 === 4.0
assert_? 4.0 === 4.0
end
think "Strict inequality checks types" do
assert_? 4 !== 4.0
end
think "Are integers booleans?" do
assert_? is_integer(true)
assert_? is_boolean(0)
end
think "Boolean OR returns left side if true, otherwise right side" do
assert_? true or true
assert_? true or false
assert_? false or true
assert_? false or false
end
think "Boolean operators check their argument's type" do
message = "argument error: " <> __?
assert_raise ArgumentError, message, fn -> 1 or true end
end
think "Other binary operators are relaxed about their argument's type" do
assert __? == 42 || 84
assert __? == 42 || nil
assert __? == nil || 84
assert __? == nil || nil
end
end