12
12
#import " TennisGame2.h"
13
13
#import " TennisGame3.h"
14
14
15
- @implementation TennisTests {
16
- int player1Score;
17
- int player2Score;
18
- NSString *expectedScore;
19
- }
20
-
15
+ @interface TennisTests (Parametrized)
16
+ + (NSArray *)parameters ;
17
+ @end
18
+ @implementation TennisTests (Parametrized)
21
19
+ (id )defaultTestSuite {
22
20
SenTestSuite *testSuite = [[SenTestSuite alloc ] initWithName: NSStringFromClass (self )];
23
21
24
- NSArray *allScores = [self allScores ];
22
+ NSArray *allScores = [self parameters ];
25
23
for (NSArray *scores in allScores) {
26
24
[self addTestWithScores: scores toTestSuite: testSuite];
27
25
}
28
26
29
27
return testSuite;
30
28
}
29
+ + (void )addTestWithScores : (NSArray *)scores toTestSuite : (SenTestSuite *)testSuite {
30
+ NSArray *testInvocations = [self testInvocations ];
31
+ for (NSInvocation *testInvocation in testInvocations) {
32
+
33
+ // Create a new instance of our test case for each method found using the given set of parameters.
34
+ SenTestCase *test = [[TennisTests alloc ] initWithInvocation: testInvocation
35
+ scores: scores];
36
+
37
+ // Add the new test instance to the suite. The OCUnit framework eventually executes the entire test suite.
38
+ [testSuite addTest: test];
39
+ }
40
+ }
41
+ @end
42
+
43
+ @implementation TennisTests {
44
+ int player1Score;
45
+ int player2Score;
46
+ NSString *expectedScore;
47
+ }
31
48
32
- + (NSArray *)allScores {
49
+ + (NSArray *)parameters {
33
50
return @[
34
51
@[ @0 , @0 , @" Love-All" ],
35
52
@[ @1 , @1 , @" Fifteen-All" ],
@@ -72,24 +89,6 @@ + (NSArray*)allScores {
72
89
];
73
90
}
74
91
75
- + (void )addTestWithScores : (NSArray *)scores toTestSuite : (SenTestSuite *)testSuite {
76
- NSArray *testInvocations = [self testInvocations ];
77
- for (NSInvocation *testInvocation in testInvocations) {
78
-
79
- // Create a new instance of our test case for each method found using the given set of parameters.
80
- SenTestCase *test = [[TennisTests alloc ] initWithInvocation: testInvocation
81
- scores: scores];
82
-
83
- // Add the new test instance to the suite. The OCUnit framework eventually executes the entire test suite.
84
- [testSuite addTest: test];
85
- }
86
- }
87
-
88
- - (NSString *)name {
89
- return [NSString stringWithFormat: @" %@ (%d ,%d ,%@ )" , [super name ], player1Score, player2Score, expectedScore];
90
- }
91
-
92
-
93
92
- (id )initWithInvocation : (NSInvocation *)invocation scores : (NSArray *)scores {
94
93
self = [super initWithInvocation: invocation];
95
94
if (self) {
@@ -100,18 +99,8 @@ - (id)initWithInvocation:(NSInvocation *)invocation scores:(NSArray *)scores {
100
99
return self;
101
100
}
102
101
103
- - (void )setUp
104
- {
105
- [super setUp ];
106
-
107
- // Set-up code here.
108
- }
109
-
110
- - (void )tearDown
111
- {
112
- // Tear-down code here.
113
-
114
- [super tearDown ];
102
+ - (NSString *)name {
103
+ return [NSString stringWithFormat: @" %@ (%d ,%d ,%@ )" , [super name ], player1Score, player2Score, expectedScore];
115
104
}
116
105
117
106
- (void )checkAllScoresForGame : (TennisGame *)game {
0 commit comments