Welcome back. We've created a special module that you can import called test.
It's not available outside this Runestone textbook environment.
In a full Python environment,
you'd use a more sophisticated module,
probably one called unit test.
But this one is a little easier to use and understand.
We're just going to use one function and it's called test equal.
It takes two values as input,
if they're equal the test passes and if they're not equal the test fails.
So, let's take a look here,
we're importing the test module and here we're
invoking the test equal function from inside the test module.
It takes two inputs, in this case,
the first input is an invocation of
the square function and the second input is just the number, 100.
When we run it, it's going to tell us that the test passes.
It passes because square of 10 is 100 and 100 equals a 100.
If I were to change one of these values,
then the test would fail.
I expected to get a 101 and it actually got 100.
So, the way that we usually do this is that we make the first value we pass in
something that we're checking on and the second value is what it ought to equal.
So, it expected to get something that equals
101 but square of 10 didn't actually equal 101.
Of course, if I have this back at 100 and I do the square of nine instead,
that's also going to fail because it got 81 but it expected 100.
Now, one thing that's important to understand about this test
equal is that it's not creating errors.
If it fails the test,
the code execution will continue on.
Let's see that.
I can have something else on the next line,
just another print statement,
when the test fails that doesn't mean that the execution will stop.
So, it said that the test failed,
but it still went on to execute line eight and print out the value four.
Here's an instructive example.
We've got a function blanked,
it's actually not correctly implemented yet but we've looked at this before.
It's something that's going to be used in the hangman game,
it takes a word,
that's the word to be guessed in the hangman game,
and some letters that had been guessed already,
and it's supposed to return a blank version of the word.
We're supposed to write a test that if we pass in the word
under and d and u have been guessed already,
what we get back should be u blank d blank blank.
In the code, we have some examples of invoking test that tests equal our challenges,
what's the right invocation that will check whether the blank function
when given under and d and u will return this?
So, the correct answer is C. Let's see why.
When we invoke the blanked function,
we have to give it two values,
the word, under, and the letters that have been already guessed.
Then we're checking whether what came back from the whole invocation of blanked,
whether that equals the u blank d blank blank.
B and A aren't quite right,
they don't have the syntax quite right.
In B, we've sort of flipped,
we've got the values in the wrong place.
The blank function takes a word and the letters that have been guessed so far,
we gave it the blank version of
the word instead of the letters that had been guessed already.
In A, the problem is that we actually pass one, two,
three different values to the blanked function and we
didn't give a second value to the test equal function.
So, we just have this parenthesis in the wrong place.
So, that's the mechanics of the test equal function of the test module.
You invoke it with two values and it checks whether those two values are equal.
It's a way to check whether a variable has
the right value or whether a function is returning the right value.
I'll see you next time.