ok so next challenge challenge number
three so the idea here is to come up
with two more tests for the remove pairs
method now normally wouldn't stop with
the two tests that we've run now
time for you to come up with two more
tests that don't test the same
functionality as those 2 existing tests so
take a look at the code and see if you
can think of another string that we
could pass to test a specific part of
the code and there's also another
special input value that we would want to
test and testing that would reveal
another bug in our code so you don't
actually have to write the tests for
this part for this challenge
if you don't want to at least just think of
what the inputs and expected outputs
would be for these scenarios so
pause the video now and i'll see you
when you get back
ok so let's have a look at our remove
pairs method again on screen so what
actual tests could we have here so first we
want to test input string that has a
length less than two obviously doing it
test here if sources less than 2 i'm
going to put a test and we'll do that
shortly so that test could be an empty
string or it could be string with a
length of one or even both scenarios
there but to the other one would also
want to do is add a test that passes
null as the string now if we want to
run that null test it would
currently file since we're not checking
for null in the removes pairs
method on screen as you can see that
let's make a few quick changes now to
cope with that
so we're going to put...
...
let's actually try that and go back
add a test for that we could do test
here and again normally as I have mentioned
you would create do one test only
per method but the simplicity of this
challenge I'm going to put them all in
this one method we do...
...
...you can see
their so we're passing null and we
should be getting back the value of null
and what what I did there was this is again where
this new feature of intellij is
quite handy that was actually the
message not expected value and of course
because we're using these sir
null we don't need to test for expected
value the actual method is testing for
null so message would be...
...let's just
run that that's pass and that's because
we've got this test here if source is
equal to null or its less than 2
return source because source was null and
you got return null fix that as well and the other
we're going to test there was a...
...
so basically that's going to give me the
tests less than two you should get back
what we pass which in this case should just
be an a so we'll run that test and do
one more test just duplicate that and
pass an empty string to make sure we
get an empty string back okay
so that's it that's that test test
scenario we just made a revision to our
code now to cater for or to test for
that null and this would be something that
you'll find does happen when you're
creating unit tests will be thinking of
conditions and then you'll realize that
you haven't tested for a particular
scenario you'll end up making
modifications as we did here to our
method to make sure that still works and
again the good thing here is that with
added these extra tests but the original
test system in there and the fact that
there's still succeeding tells us that
the changes that we've made to the
method haven't broken anything which is
obviously the whole point of a unit test
to make sure you're not breaking
anything when you're changing or adding
functionality as well as testing
everything in that method
alright let's move on to the next
challenge challenge 4
going to add a test for every for
the every ninth char method so you want
to test the following scenario so the
input the char containing the
letters hello in order as well as
n equals 2 and the output should be the
char array containing the letters E and
L in that order so see how you go with that add a
unit test for that pause the video and
I'll see you when you get back alright
so since we're testing in an array result we
need to use the insert array equals
method so let's do that in the equal nth char
so going to delete that....
....
...
...now to test this
we actually need to use these certs
array equals method and that's because
when testing arrays the cert equals
method only returns true if the if
the arrays are the exact same instance
so it's the wrong method to use in this
case just to confirm that lets actually
test the array to see that it works so we're
going to use an assert....
and if that doesn't come up for you just like for me go over here
here click on import
static method you can see up there and
then what we want to test in here is
we need to create a new char array
which would be what would be expected
output is so we're going to do...
...
if we run that method that should work
you can see that's worked ok and just to
confirm if we do changes to use cert
equals and try to run that we do get
that failure and that's because the two
char arrays are actually different and
assert equals is only checking to see if
the arrays are the exact same instance
that's the reason that we're using that
so let's undo that change now we're back
to where we were which was these cert
arrays equals running that and we are good
to go again
alright so let's move on to the next
challenge challenge number five so add a
test for the case when n is greater than
the length of the array they can add a
new test case or you can actually add
the test to the existing test case method
it's up to you as to which way you want
to go
so again write that test that tests the
case when the value of n is greater than
the length of the string and you can add
you test case or you can add the test to
the existing test case up to you pause the
video and I'll see you when you get back
ok so for this one we're just going to
put the test on the next line up here so
i'm going to do...
...
..
...
ok let's run that ok that passes you can
see that time we've got the right
response there next challenge
challenge number six
that's to add a test for the null if odd
length method so in actual facts the
challenge is to write two tests for that
method you want to include both tests in
the null if odd length test
method in one of them passed a string its going
to even length and in the second test
passes string that's got an odd length so
that's the challenge
pause the video I'll see you when you
get back
ok so when testing for null and not null
we want to use the acert null and acert not null
methods
let's go down to our null if odd length
method test...
...
...so lets
actually run that test passes challenge
number seven
you want to add a test now for the
converter method so test the converter
method with the following input and
output the input should be a equals 10 b equals 5
and the output we should be getting
back is 300 so add that test
pause the video and I'll see you when
you get back
ok so let's add that test will
remove this fail call first
from our converter test and then we
want to do....
...
...lets actually run that
and you see that that's worked
successfully alright I'm going to end
the video here in the next video we'll
finish off the challenges with the
remaining 3 i'll see you in the next
video