objective c - Unit tests with strings (Bloc Ios Development) -
i'm going through bloc bootcamp , need little code. need these unit tests pass. below 2 implementation files: changes methods done in stringcheese.m while stringcheesetests.m displays failures. i've copied on 1 failure can work through rest. appreciated.
stringcheesetests.m
- (void)testthatcheesefavoritingworks { nsstring *ricottastring = @"ricotta"; nsstring *favoritecheese = [self.stringcheese favoritecheesestringwithcheese:ricottastring]; xctassertequalobjects(favoritecheese, @"my favorite cheese ricotta.", @"incorrect favorite cheese string returned."); nsstring *goatstring = @"goat"; favoritecheese = [self.stringcheese favoritecheesestringwithcheese:goatstring]; xctassertequalobjects(favoritecheese, @"my favorite cheese goat.", @"incorrect favorite cheese string returned."); }
stringcheese.m
- (nsstring *) favoritecheesestringwithcheese:(nsstring *)cheesename { **//work here** return nil; }
well, if understood correctly: you're looking write in implmentation of favoritecheesestringwithcheese:
such passes associated test.
what need here analogous solving maze starting @ finish , working way start (at least that's how did kid).
additionally, need understand parameters being passed xctassertequalobjects
:
// generates failure when [a1 isequal:a2] false (or 1 nil , other not) xctassertequalobjects(a1, a2, format...)
from derive a2
in case my favorite cheese ricotta
, need ensure a1
give string ... meaning favoritecheesestringwithcheese:
needs provide that.
the method signature favoritecheesestringwithcheese:
takes in string value , returns string. test, know that:
passing
ricotta
parameter should returnmy favorite cheese ricotta
passing
goat
parameter should returnmy favorite cheese goat
the constant value in case string my favorite cheese
variable being parameter cheesename
. in order tests pass, need ensure nsstring
pass in gets appended constant nsstring
, value gets returned. (mind you, case , whitespace matter).
i hope answers question without giving away. :)
edit: expanded answer
your method in stringcheese.m
this:
(nsstring *)favoritecheesestringwithcheese: (nsstring *)cheesename{ nsstring *cheeseintro = @"my favorite cheese "; nsstring *favoritecheeseintro = [cheeseintro stringbyappendingstring: cheesename]; return favoritecheeseintro; }
so, when you're calling method:
// declaring variable @property (nonatomic, strong) stringcheese *cheese; // further down in code self.cheese = [[stringcheese alloc] init]; nsstring *myfavoritecheese = [self.cheese favoritecheesewithcheese:@"ricota"]; // myfavoritecheese "my favorite cheese ricotta"
Comments
Post a Comment