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