Keeping Bugs at Bay2:22 with Alena Holligan
Testing helps keep us from introducing a bug into our code, and it also helped us diagnose what the problem was.
We'll go into our test and we'll copy our digraph test. 0:01 We'll change this to trigraph. 0:10 And we'll need a trigraphed word. 0:13 I'll use streak. 0:18 The expected output will be eakstray. 0:22 And let's run our test again. 0:27 As expected, our third test fails. 0:31 And we can see that it only moved 0:34 the first two letters instead of the first three. 0:37 Back in our converter, we'll start by adding our trigraph array. 0:42 Then we can add a new variable for firstThreeLetters. 0:48 Substring, the word, 0:54 start at the beginning, and give the first three letters. 1:00 Next, we can copy our if statement to create an else if. 1:04 We'll change to first, Three letters, and first three letters. 1:11 Start at the third character, and use our trigraph. 1:22 And now let's run our test again. 1:27 We get our same failure, but why? 1:30 Again, in our expected results, compared to our actual results, 1:34 we see that only the first two letters of streak has been moved. 1:39 That's because we're checking for digraphs first. 1:44 An ST is a digraph. 1:48 And STR is a trigraph. 1:50 Our test helps keep us from introducing a bug into our code. 1:53 And it also help this diagnose what the problem was. 1:58 We need to move our trigraph check before our di-graph check. 2:02 Now let's run our test again. 2:16 And this time they all pass. 2:20
You need to sign up for Treehouse in order to download course files.Sign up