Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koan/about control #1

Open
wants to merge 15 commits into
base: Oscar
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .path_progress
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1,2,2,3,1,1,1,2,3,4,4,4,4,6,7,0,1,2,2,2,2,3,3,4,4,4,5,6,6,6,6,7,7,8,9,10,11,11,12,13,13,0,1,2,3,3,4,5,6,6,7,8,9,10,10,10,10,11,11,11,11,1,2,3,3,3,4,4,4,5,6,7,8,8,9,9,10,11,12,13,13,13,14,15,16,17,18,18,19,20,20,21,21,22,22,22,22,23,24,24,25,25,26
1,2,2,3,1,1,1,2,3,4,4,4,4,6,7,0,1,2,2,2,2,3,3,4,4,4,5,6,6,6,6,7,7,8,9,10,11,11,12,13,13,0,1,2,3,3,4,5,6,6,7,8,9,10,10,10,10,11,11,11,11,1,2,3,3,3,4,4,4,5,6,7,8,8,9,9,10,11,12,13,13,13,14,15,16,17,18,18,19,20,20,21,21,22,22,22,22,23,24,24,25,25,26,1,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14
34 changes: 17 additions & 17 deletions about_control_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def test_if_then_else_statements
else
result = :false_value
end
assert_equal __, result
assert_equal :true_value, result
end

def test_if_then_statements
result = :default_value
if true
result = :true_value
end
assert_equal __, result
assert_equal :true_value, result
end

def test_if_statements_return_values
Expand All @@ -25,14 +25,14 @@ def test_if_statements_return_values
else
:false_value
end
assert_equal __, value
assert_equal :true_value, value

value = if false
:true_value
else
:false_value
end
assert_equal __, value
assert_equal :false_value, value

# NOTE: Actually, EVERY statement in Ruby will return a value, not
# just if statements.
Expand All @@ -42,42 +42,42 @@ def test_if_statements_with_no_else_with_false_condition_return_value
value = if false
:true_value
end
assert_equal __, value
assert_equal nil, value
end

def test_condition_operators
assert_equal __, (true ? :true_value : :false_value)
assert_equal __, (false ? :true_value : :false_value)
assert_equal :true_value, (true ? :true_value : :false_value)
assert_equal :false_value, (false ? :true_value : :false_value)
end

def test_if_statement_modifiers
result = :default_value
result = :true_value if true

assert_equal __, result
assert_equal :true_value, result
end

def test_unless_statement
result = :default_value
unless false # same as saying 'if !false', which evaluates as 'if true'
result = :false_value
end
assert_equal __, result
assert_equal :false_value, result
end

def test_unless_statement_evaluate_true
result = :default_value
unless true # same as saying 'if !true', which evaluates as 'if false'
result = :true_value
end
assert_equal __, result
assert_equal :default_value, result
end

def test_unless_statement_modifier
result = :default_value
result = :false_value unless false

assert_equal __, result
assert_equal :false_value, result
end

def test_while_statement
Expand All @@ -87,7 +87,7 @@ def test_while_statement
result = result * i
i += 1
end
assert_equal __, result
assert_equal 3628800, result
end

def test_break_statement
Expand All @@ -98,7 +98,7 @@ def test_break_statement
result = result * i
i += 1
end
assert_equal __, result
assert_equal 3628800, result
end

def test_break_statement_returns_values
Expand All @@ -108,7 +108,7 @@ def test_break_statement_returns_values
i += 1
end

assert_equal __, result
assert_equal 2, result
end

def test_next_statement
Expand All @@ -119,7 +119,7 @@ def test_next_statement
next if (i % 2) == 0
result << i
end
assert_equal __, result
assert_equal [1,3,5,7,9], result
end

def test_for_statement
Expand All @@ -128,15 +128,15 @@ def test_for_statement
for item in array
result << item.upcase
end
assert_equal [__, __, __], result
assert_equal ["FISH", "AND", "CHIPS"], result
end

def test_times_statement
sum = 0
10.times do
sum += 1
end
assert_equal __, sum
assert_equal 10, sum
end

end