1+ package hotciv .standard ;
2+
3+ import hotciv .framework .*;
4+
5+ import org .junit .Before ;
6+ import org .junit .Test ;
7+
8+ import static hotciv .framework .GameConstants .ARCHER ;
9+ import static hotciv .framework .GameConstants .SETTLER ;
10+ import static org .hamcrest .CoreMatchers .is ;
11+ import static org .junit .Assert .assertNull ;
12+ import static org .junit .Assert .assertThat ;
13+
14+
15+ public class thetaCiv_tests {
16+ private GameImpl game ; //Changed Game to GameImpl -TPD
17+
18+ /**
19+ * Fixture for thetaCiv testing.
20+ */
21+ @ Before
22+ public void setUp () {
23+ game = new GameImpl (GameType .thetaCiv , 2 );
24+ }
25+
26+ //..........Unit Tests...........//
27+
28+ @ Test
29+ public void settlerActionToCity (){
30+ //Player red has a settler at (3,4) in the test game constructor
31+ Position posSettler = new Position (3 , 4 );
32+ game .createUnitAt (posSettler , SETTLER , Player .RED );
33+ //game.setCityAt(posSettler, game.getUnitAt(posSettler).getOwner()); //old code
34+ game .performUnitActionAt (posSettler ); //with refactoring
35+ assertThat (game .getCityAt (posSettler ).getOwner (), is (Player .RED ) );
36+ assertThat (game .getCityAt (posSettler ).getSize (), is (1 ));
37+ assertNull (game .getUnitAt (posSettler ));
38+ }
39+
40+ @ Test
41+ public void archerFortifyDoublesDefense (){ //simulate fortifying an archer
42+ Position posArcher = new Position (0 ,2 );
43+ game .createUnitAt (posArcher , ARCHER , Player .RED );
44+ game .getUnitAt (posArcher ).setDefensiveStrength (2 );
45+ game .performUnitActionAt (posArcher );
46+ assertThat (game .getUnitAt (posArcher ).getDefensiveStrength (), is (4 ));
47+ }
48+ @ Test
49+ public void archerFortifyHalvesDefense (){ //simulate fortifying an already fortified archer
50+ Position posArcher = new Position (0 ,2 );
51+ game .createUnitAt (posArcher , ARCHER , Player .RED );
52+ game .getUnitAt (posArcher ).setDefensiveStrength (1 );
53+ game .getUnitAt (posArcher ).fortify ();
54+ game .performUnitActionAt (posArcher );
55+ assertThat (game .getUnitAt (posArcher ).getDefensiveStrength (), is (1 ));
56+ }
57+
58+ //...............Integration Testing...................//
59+
60+ @ Test
61+ public void settlerActionToCityIntegrated (){
62+ //Player red has a settler at (3,4) in the test game constructor
63+ Position posSettler = new Position (3 , 4 );
64+ game .createUnitAt (posSettler , SETTLER , Player .RED );
65+ game .performUnitActionAt (posSettler );
66+ assertThat (game .getCityAt (posSettler ).getOwner (), is (Player .RED ) );
67+ assertThat (game .getCityAt (posSettler ).getSize (), is (1 ));
68+ assertNull (game .getUnitAt (posSettler ));
69+ }
70+
71+ @ Test
72+ public void archerFortifyDoublesDefenseIntegrated (){ //simulate fortifying an archer
73+ Position posArcher = new Position (0 ,2 );
74+ game .createUnitAt (posArcher , ARCHER , Player .RED );
75+ game .getUnitAt (posArcher ).setDefensiveStrength (2 );
76+ game .performUnitActionAt (posArcher );
77+ assertThat (game .getUnitAt (posArcher ).getDefensiveStrength (), is (4 ));
78+ }
79+ @ Test
80+ public void archerFortifyHalvesDefenseIntegrated (){ //simulate fortifying an already fortified archer
81+ Position posArcher = new Position (0 ,2 );
82+ game .createUnitAt (posArcher , ARCHER , Player .RED );
83+ game .getUnitAt (posArcher ).setDefensiveStrength (1 );
84+ game .getUnitAt (posArcher ).fortify ();
85+ game .performUnitActionAt (posArcher );
86+ assertThat (game .getUnitAt (posArcher ).getDefensiveStrength (), is (1 ));
87+ }
88+ }
0 commit comments