1. 31
    Rustlings test3: Testing a function multiple times
    39s

Rustlings test3: Testing a function multiple times

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet

Chris Biscardi: [0:00] Exercises test3 is a test for the Tests section that we just went through. Currently, the comment in this file tells us that the test isn't testing our function, make it do so in such a way that the test passes. Then, we have to write a second test that tests what happens when we call our function "times_two" with a negative number.

[0:16] Again, we have our public function "times_two" that takes a number and returns a number. The body of the function implicitly returns number times two, and then we configure our test module. In this case, returns_twice_of_positive_numbers uses the assert_equal! Macro, to test times_two on four, which is eight.

[0:33] Now we have to do the same thing for negative four, which will be negative eight. We can test to make sure that our test is running by making it fail.