Skip to content

Instantly share code, notes, and snippets.

@justinwyer
Last active December 12, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save justinwyer/4750154 to your computer and use it in GitHub Desktop.
Save justinwyer/4750154 to your computer and use it in GitHub Desktop.
@implementation CardTest
- (void)testShouldKnowCardCannotMatchEmptyCardList {
Card *card = [Card new];
NSArray *otherCards = [NSArray new];
STAssertEquals(0, [card match:otherCards], @"Should not match empty card list.");
}
- (void)testShouldMatchCardWhenCardListContainsCardWithSameContent {
Card *card = [[Card alloc] initWithContents:@"Test Card"];
Card *matchingCard = [[Card alloc] initWithContents:@"Test Card"];
Card *differentCard = [[Card alloc] initWithContents:@"Different Test Card"];
NSMutableArray *cards = [[NSMutableArray alloc] initWithObjects:differentCard, differentCard, matchingCard, nil];
time_t seed = time(nil);
srandom(seed);
for (NSInteger index = cards.count - 1; index > 0; index--) {
NSInteger swapIndex = random() % index;
[cards exchangeObjectAtIndex:index withObjectAtIndex:swapIndex];
}
int result = [card match:cards];
STAssertEquals(1, result, [NSString stringWithFormat:@"Should match when matching card is in list. Random seed: %d", seed]);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment