-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathabout_true_and_false.rb
More file actions
34 lines (29 loc) · 958 Bytes
/
about_true_and_false.rb
File metadata and controls
34 lines (29 loc) · 958 Bytes
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
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutTrueAndFalse < Neo::Koan
def truth_value(condition)
if condition
:true_stuff
else
:false_stuff
end
end
def test_true_is_treated_as_true
assert_equal :true_stuff, truth_value(true)
end
def test_false_is_treated_as_false
assert_equal :false_stuff, truth_value(false)
end
# Only false and nil is considered false. Anything else is true.
def test_nil_is_treated_as_false_too
assert_equal :false_stuff, truth_value(nil)
end
# All values tested against except for false and nil is considered true
def test_everything_else_is_treated_as_true
assert_equal :true_stuff, truth_value(1)
assert_equal :true_stuff, truth_value(0)
assert_equal :true_stuff, truth_value([])
assert_equal :true_stuff, truth_value({})
assert_equal :true_stuff, truth_value("Strings")
assert_equal :true_stuff, truth_value("")
end
end