forked from dojo-toulouse/elixir-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
about_numbers_and_booleans.exs
executable file
·95 lines (74 loc) · 2.3 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
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
#!/usr/bin/env elixir
ExUnit.start
defmodule About_Numbers_and_booleans do
use ExUnit.Case
use Koans
think "Basics numbers types" do
an_integer = __?
a_float = 42.0
assert is_integer(an_integer)
assert_? is_float(a_float)
assert_? is_float(an_integer)
assert_? is_integer(a_float)
end
think "Is a hexadecimal number treated as an integer" do
assert_? is_integer(0x2A)
end
think "Answer to the Ultimate Question of Life, the Universe, and Everything" do
an_hex = 0x20
a_dec = 10
assert an_hex + a_dec == __?
end
think "You can use _ as separator in integer" do
an_integer = 100_000_000
assert_? is_integer(an_integer)
end
think "Value equality operator has an usual expectation" do
an_integer = 4
a_float = 4.0
assert_? an_integer == a_float
end
think "Value inequality operator has an usual expectation" do
an_integer = 4
a_float = 2.0
assert_? an_integer != a_float
end
think "Strict equality operator take care about types" do
an_integer = 4
a_float = 4.0
assert_? an_integer === a_float
end
think "Strict inequality operator take care about types" do
an_integer = 4
a_float = 4.0
assert_? an_integer !== a_float
end
think "Comparing two values considering type" do
an_integer = 4.0
a_float = 4.0
assert_? an_integer === a_float
end
think "Are booleans integers ?" do
assert_? is_integer(true)
assert_? is_boolean(0)
end
think "Booleans are atoms" do
assert_? is_atom(true)
assert :true == __?
end
think "That's true if a_boolean is true ortherwise b_boolean" do
a_boolean = false
b_boolean = true
assert_? a_boolean or b_boolean
end
think "Operator || is a relaxed boolean operator, that's true if a_variable or b_variable isn't nil" do
a_variable = 42
b_variable = nil
assert_? a_variable || b_variable
end
think "Operator && is a relaxed boolean operator, that's true if a_variable and b_variable isn't nil" do
a_variable = 42
b_variable = 5.0
assert_? a_variable && b_variable
end
end