1 00:00:07,890 --> 00:00:14,680 Welcome back. We've created a special module that you can import called test. 2 00:00:14,680 --> 00:00:18,535 It's not available outside this Runestone textbook environment. 3 00:00:18,535 --> 00:00:20,560 In a full Python environment, 4 00:00:20,560 --> 00:00:22,240 you'd use a more sophisticated module, 5 00:00:22,240 --> 00:00:24,385 probably one called unit test. 6 00:00:24,385 --> 00:00:27,160 But this one is a little easier to use and understand. 7 00:00:27,160 --> 00:00:31,555 We're just going to use one function and it's called test equal. 8 00:00:31,555 --> 00:00:34,780 It takes two values as input, 9 00:00:34,780 --> 00:00:40,585 if they're equal the test passes and if they're not equal the test fails. 10 00:00:40,585 --> 00:00:43,310 So, let's take a look here, 11 00:00:44,100 --> 00:00:48,010 we're importing the test module and here we're 12 00:00:48,010 --> 00:00:51,940 invoking the test equal function from inside the test module. 13 00:00:51,940 --> 00:00:55,850 It takes two inputs, in this case, 14 00:00:55,850 --> 00:00:58,570 the first input is an invocation of 15 00:00:58,570 --> 00:01:03,575 the square function and the second input is just the number, 100. 16 00:01:03,575 --> 00:01:08,630 When we run it, it's going to tell us that the test passes. 17 00:01:10,110 --> 00:01:16,375 It passes because square of 10 is 100 and 100 equals a 100. 18 00:01:16,375 --> 00:01:20,055 If I were to change one of these values, 19 00:01:20,055 --> 00:01:22,720 then the test would fail. 20 00:01:23,070 --> 00:01:28,065 I expected to get a 101 and it actually got 100. 21 00:01:28,065 --> 00:01:32,915 So, the way that we usually do this is that we make the first value we pass in 22 00:01:32,915 --> 00:01:38,750 something that we're checking on and the second value is what it ought to equal. 23 00:01:38,750 --> 00:01:41,880 So, it expected to get something that equals 24 00:01:41,880 --> 00:01:46,265 101 but square of 10 didn't actually equal 101. 25 00:01:46,265 --> 00:01:51,950 Of course, if I have this back at 100 and I do the square of nine instead, 26 00:01:51,950 --> 00:01:57,830 that's also going to fail because it got 81 but it expected 100. 27 00:01:57,830 --> 00:02:01,490 Now, one thing that's important to understand about this test 28 00:02:01,490 --> 00:02:05,255 equal is that it's not creating errors. 29 00:02:05,255 --> 00:02:06,915 If it fails the test, 30 00:02:06,915 --> 00:02:09,510 the code execution will continue on. 31 00:02:09,510 --> 00:02:12,220 Let's see that. 32 00:02:12,760 --> 00:02:16,580 I can have something else on the next line, 33 00:02:16,580 --> 00:02:18,665 just another print statement, 34 00:02:18,665 --> 00:02:23,060 when the test fails that doesn't mean that the execution will stop. 35 00:02:23,060 --> 00:02:25,115 So, it said that the test failed, 36 00:02:25,115 --> 00:02:29,940 but it still went on to execute line eight and print out the value four. 37 00:02:29,940 --> 00:02:32,315 Here's an instructive example. 38 00:02:32,315 --> 00:02:34,525 We've got a function blanked, 39 00:02:34,525 --> 00:02:38,450 it's actually not correctly implemented yet but we've looked at this before. 40 00:02:38,450 --> 00:02:41,330 It's something that's going to be used in the hangman game, 41 00:02:41,330 --> 00:02:44,895 it takes a word, 42 00:02:44,895 --> 00:02:47,205 that's the word to be guessed in the hangman game, 43 00:02:47,205 --> 00:02:49,550 and some letters that had been guessed already, 44 00:02:49,550 --> 00:02:53,330 and it's supposed to return a blank version of the word. 45 00:02:53,330 --> 00:02:57,920 We're supposed to write a test that if we pass in the word 46 00:02:57,920 --> 00:03:03,735 under and d and u have been guessed already, 47 00:03:03,735 --> 00:03:10,360 what we get back should be u blank d blank blank. 48 00:03:10,730 --> 00:03:17,240 In the code, we have some examples of invoking test that tests equal our challenges, 49 00:03:17,240 --> 00:03:22,070 what's the right invocation that will check whether the blank function 50 00:03:22,070 --> 00:03:28,050 when given under and d and u will return this? 51 00:03:29,780 --> 00:03:34,950 So, the correct answer is C. Let's see why. 52 00:03:34,950 --> 00:03:37,295 When we invoke the blanked function, 53 00:03:37,295 --> 00:03:39,594 we have to give it two values, 54 00:03:39,594 --> 00:03:45,370 the word, under, and the letters that have been already guessed. 55 00:03:45,370 --> 00:03:52,030 Then we're checking whether what came back from the whole invocation of blanked, 56 00:03:52,030 --> 00:03:56,930 whether that equals the u blank d blank blank. 57 00:03:57,890 --> 00:04:00,360 B and A aren't quite right, 58 00:04:00,360 --> 00:04:02,515 they don't have the syntax quite right. 59 00:04:02,515 --> 00:04:05,690 In B, we've sort of flipped, 60 00:04:06,020 --> 00:04:09,335 we've got the values in the wrong place. 61 00:04:09,335 --> 00:04:14,035 The blank function takes a word and the letters that have been guessed so far, 62 00:04:14,035 --> 00:04:16,190 we gave it the blank version of 63 00:04:16,190 --> 00:04:19,040 the word instead of the letters that had been guessed already. 64 00:04:19,040 --> 00:04:24,095 In A, the problem is that we actually pass one, two, 65 00:04:24,095 --> 00:04:27,590 three different values to the blanked function and we 66 00:04:27,590 --> 00:04:31,250 didn't give a second value to the test equal function. 67 00:04:31,250 --> 00:04:35,400 So, we just have this parenthesis in the wrong place. 68 00:04:35,800 --> 00:04:40,220 So, that's the mechanics of the test equal function of the test module. 69 00:04:40,220 --> 00:04:45,995 You invoke it with two values and it checks whether those two values are equal. 70 00:04:45,995 --> 00:04:48,170 It's a way to check whether a variable has 71 00:04:48,170 --> 00:04:51,905 the right value or whether a function is returning the right value. 72 00:04:51,905 --> 00:04:54,510 I'll see you next time.