-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCombat.m
131 lines (89 loc) · 3.42 KB
/
TestCombat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// TestCombat.m
// MathWars
//
// Created by Inf on 01.03.10.
// Copyright 2010 Soulteam. All rights reserved.
//
#import <OCMock/OCMock.h>
#import "TestCombat.h"
#import "PlayerProtocol.h"
#import "Unit.h"
#define typeof __typeof__
@implementation TestCombat
-(void)setUp {
mockPlayer = [OCMockObject mockForProtocol:@protocol(PlayerProtocol)];
mockEnemy = [OCMockObject mockForProtocol:@protocol(PlayerProtocol)];
mockPlayerUnit = [OCMockObject mockForClass:[Unit class]];
[[[mockPlayerUnit stub] andReturn:mockPlayer] owner];
mockEnemyUnit = [OCMockObject mockForClass:[Unit class]];
[[[mockEnemyUnit stub] andReturn:mockEnemy] owner];
mockPlayerPuzzle = [OCMockObject mockForClass:[Puzzle class]];
mockEnemyPuzzle = [OCMockObject mockForClass:[Puzzle class]];
mockDelegate = [OCMockObject mockForProtocol:@protocol(CombatObserver)];
combat = [[Combat alloc] initWithAttacker:mockPlayerUnit andProtector:mockEnemyUnit andDelegate:mockDelegate];
}
-(void)tearDown {
[combat release];
}
-(void)testRoundStart {
[[[mockPlayer expect] andReturn:mockPlayerPuzzle] createPuzzleOfDifficulty:1 withDelegate:combat];
[[[mockEnemy expect] andReturn:mockEnemyPuzzle] copyPuzzle:mockPlayerPuzzle];
[combat startRound];
[mockPlayer verify];
}
-(void)testRoundWithPlayerLose {
int8_t health = 2;
uint8_t attack = 1;
[[[mockPlayer stub] andReturn:mockPlayerPuzzle] createPuzzleOfDifficulty:1 withDelegate:combat];
[[[mockEnemy stub] andReturn:mockEnemyPuzzle] copyPuzzle:mockPlayerPuzzle];
[[[mockPlayerUnit stub] andReturnValue:OCMOCK_VALUE(health)] health];
[[[mockEnemyUnit stub] andReturnValue:OCMOCK_VALUE(attack)] attack];
[[[mockEnemyUnit stub] andReturnValue:OCMOCK_VALUE(health)] health];
[[mockPlayerUnit expect] setHealth:1];
[[mockPlayerPuzzle expect] fail];
[[mockDelegate expect] unitAttacked:mockEnemyUnit];
[combat startRound];
[combat puzzleWasSolved:mockEnemyPuzzle];
[mockPlayerPuzzle verify];
[mockPlayerUnit verify];
[mockDelegate verify];
}
-(void)testRoundWithPlayerWin {
int8_t health = 2;
uint8_t attack = 1;
[[[mockPlayer stub] andReturn:mockPlayerPuzzle] createPuzzleOfDifficulty:1 withDelegate:combat];
[[[mockEnemy stub] andReturn:mockEnemyPuzzle] copyPuzzle:mockPlayerPuzzle];
[[[mockPlayerUnit stub] andReturnValue:OCMOCK_VALUE(health)] health];
[[[mockEnemyUnit stub] andReturnValue:OCMOCK_VALUE(health)] health];
[[[mockPlayerUnit stub] andReturnValue:OCMOCK_VALUE(attack)] attack];
[[mockEnemyUnit expect] setHealth:1];
[[mockEnemyPuzzle expect] fail];
[[mockDelegate expect] unitAttacked:mockPlayerUnit];
[combat startRound];
[combat puzzleWasSolved:mockPlayerPuzzle];
[mockEnemyPuzzle verify];
[mockEnemyUnit verify];
[mockDelegate verify];
}
-(void)testRoundWithTwoErrors {
id mockCombat = [OCMockObject partialMockForObject:combat];
[[[mockPlayer stub] andReturn:mockPlayerPuzzle] createPuzzleOfDifficulty:1 withDelegate:combat];
[[[mockEnemy stub] andReturn:mockEnemyPuzzle] copyPuzzle:mockPlayerPuzzle];
[mockCombat startRound];
[mockCombat puzzleWasFailed:mockPlayerPuzzle];
[[mockCombat expect] startRound];
[mockCombat puzzleWasFailed:mockEnemyPuzzle];
[mockCombat verify];
}
-(void)setNullPlayerHealth {
uint8_t health = 0;
[[[mockPlayerUnit stub] andReturnValue:OCMOCK_VALUE(health)] health];
}
-(void)testRoundWithPlayerDeath {
//Написать позже
}
-(void)testRoundWithEnemyDeath {
//Написать позже
}
@end