I am finishing up the last two Assert Equality Koans. They are similar so I put them together on this blog.
# Some ways of asserting equality are better than others.
def test_a_better_way_of_asserting_equality
expected_value = __
actual_value = 1 + 1
assert_equal expected_value, actual_value
end
# Sometimes we will ask you to fill in the values
def test_fill_in_values
assert_equal __, 1 + 1
end
Solution
def test_a_better_way_of_asserting_equality
expected_value = 1 + 1
actual_value = 1 + 1
assert_equal expected_value, actual_value
end
# Sometimes we will ask you to fill in the values
def test_fill_in_values
assert_equal 2, 1 + 1
end
These two are essentially the same. When you look at the third line of the first Koan, it says assert_equal expected_value, actual_value.
Assert_equal is asking the next two values that you pass in will be equal. So you look at where the two variables are defined.
Expected_value, actual_value,
you see that the solution is to write a value to expected_value that is equal to actual value and the last line will equate to true.
There are two ways to set two values to equal each other. Using the == operator and to call Assert_equal and pass two variables that are equal. (Assert_equal __ , __ )
Brought to you by KENYACODE. Can you code?
No comments:
Post a Comment