From 248c53b44503c72fa7e34cd52e58bbecacafea9c Mon Sep 17 00:00:00 2001 From: Stefan van den Oord Date: Fri, 31 May 2013 20:26:35 +0200 Subject: [PATCH] Refactored test so that parametrized part is separated better and more explicit --- Tennis/objc/.idea/workspace.xml | 37 +++++++-------- Tennis/objc/TennisTests/TennisTests.m | 65 +++++++++++---------------- 2 files changed, 42 insertions(+), 60 deletions(-) diff --git a/Tennis/objc/.idea/workspace.xml b/Tennis/objc/.idea/workspace.xml index 6a966889..71136a7c 100644 --- a/Tennis/objc/.idea/workspace.xml +++ b/Tennis/objc/.idea/workspace.xml @@ -2,19 +2,19 @@ - + - + - + @@ -49,21 +49,13 @@ - - - - - - - - - - + + @@ -319,7 +311,7 @@ - + @@ -400,13 +392,6 @@ - - - - - - - @@ -456,11 +441,19 @@ + + + + + + + - + + diff --git a/Tennis/objc/TennisTests/TennisTests.m b/Tennis/objc/TennisTests/TennisTests.m index f1c0c112..6a4a2ea1 100644 --- a/Tennis/objc/TennisTests/TennisTests.m +++ b/Tennis/objc/TennisTests/TennisTests.m @@ -12,24 +12,41 @@ #import "TennisGame2.h" #import "TennisGame3.h" -@implementation TennisTests { - int player1Score; - int player2Score; - NSString *expectedScore; -} - +@interface TennisTests (Parametrized) ++ (NSArray*)parameters; +@end +@implementation TennisTests (Parametrized) + (id)defaultTestSuite { SenTestSuite *testSuite = [[SenTestSuite alloc] initWithName:NSStringFromClass(self)]; - NSArray *allScores = [self allScores]; + NSArray *allScores = [self parameters]; for (NSArray *scores in allScores) { [self addTestWithScores:scores toTestSuite:testSuite]; } return testSuite; } ++ (void)addTestWithScores:(NSArray *)scores toTestSuite:(SenTestSuite *)testSuite { + NSArray *testInvocations = [self testInvocations]; + for (NSInvocation *testInvocation in testInvocations) { -+ (NSArray*)allScores { + // Create a new instance of our test case for each method found using the given set of parameters. + SenTestCase *test = [[TennisTests alloc] initWithInvocation:testInvocation + scores:scores]; + + // Add the new test instance to the suite. The OCUnit framework eventually executes the entire test suite. + [testSuite addTest:test]; + } +} +@end + +@implementation TennisTests { + int player1Score; + int player2Score; + NSString *expectedScore; +} + ++ (NSArray*)parameters { return @[ @[ @0, @0, @"Love-All"], @[ @1, @1, @"Fifteen-All"], @@ -72,24 +89,6 @@ ]; } -+ (void)addTestWithScores:(NSArray *)scores toTestSuite:(SenTestSuite *)testSuite { - NSArray *testInvocations = [self testInvocations]; - for (NSInvocation *testInvocation in testInvocations) { - - // Create a new instance of our test case for each method found using the given set of parameters. - SenTestCase *test = [[TennisTests alloc] initWithInvocation:testInvocation - scores:scores]; - - // Add the new test instance to the suite. The OCUnit framework eventually executes the entire test suite. - [testSuite addTest:test]; - } -} - -- (NSString *)name { - return [NSString stringWithFormat:@"%@ (%d,%d,%@)", [super name], player1Score, player2Score, expectedScore]; -} - - - (id)initWithInvocation:(NSInvocation *)invocation scores:(NSArray *)scores { self = [super initWithInvocation:invocation]; if (self) { @@ -100,18 +99,8 @@ return self; } -- (void)setUp -{ - [super setUp]; - - // Set-up code here. -} - -- (void)tearDown -{ - // Tear-down code here. - - [super tearDown]; +- (NSString *)name { + return [NSString stringWithFormat:@"%@ (%d,%d,%@)", [super name], player1Score, player2Score, expectedScore]; } - (void)checkAllScoresForGame:(TennisGame *)game {