|
| 1 | +package hotciv.standard; |
| 2 | + |
| 3 | +import hotciv.framework.GameType; |
| 4 | +import hotciv.framework.Player; |
| 5 | +import hotciv.framework.Position; |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import static org.hamcrest.CoreMatchers.is; |
| 10 | +import static org.junit.Assert.assertThat; |
| 11 | + |
| 12 | +/** Skeleton class for AlphaCiv test cases |
| 13 | +
|
| 14 | + Updated Oct 2015 for using Hamcrest matchers |
| 15 | +
|
| 16 | + This source code is from the book |
| 17 | + "Flexible, Reliable Software: |
| 18 | + Using Patterns and Agile Development" |
| 19 | + published 2010 by CRC Press. |
| 20 | + Author: |
| 21 | + Henrik B Christensen |
| 22 | + Department of Computer Science |
| 23 | + Aarhus University |
| 24 | + |
| 25 | + Please visit http://www.baerbak.com/ for further information. |
| 26 | +
|
| 27 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 28 | + you may not use this file except in compliance with the License. |
| 29 | + You may obtain a copy of the License at |
| 30 | + |
| 31 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 32 | + |
| 33 | + Unless required by applicable law or agreed to in writing, software |
| 34 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 35 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 36 | + See the License for the specific language governing permissions and |
| 37 | + limitations under the License. |
| 38 | +
|
| 39 | +*/ |
| 40 | +public class betaCiv_tests { |
| 41 | + private GameImpl game; //Changed Game to GameImpl -TPD |
| 42 | + |
| 43 | + /** |
| 44 | + * Fixture for alphaCiv testing. |
| 45 | + */ |
| 46 | + @Before |
| 47 | + public void setUp() { |
| 48 | + game = new GameImpl(GameType.betaCiv); |
| 49 | + } |
| 50 | + |
| 51 | + // FRS p. 455 states that 'Red is the first player to take a turn'. |
| 52 | + |
| 53 | + @Test |
| 54 | + public void betaCiv_DynamicWorldAging() { |
| 55 | + |
| 56 | + // 100 Years per turn pre- 100BC |
| 57 | + for (int i = 0; i < 39; i++) { |
| 58 | + game.endOfTurn(); |
| 59 | + } |
| 60 | + assertThat(game.getAge(), is(-100)); |
| 61 | + |
| 62 | + // Next turn is 1BC |
| 63 | + game.endOfTurn(); |
| 64 | + assertThat(game.getAge(), is(-1)); |
| 65 | + |
| 66 | + // Next turn is 1AD |
| 67 | + game.endOfTurn(); |
| 68 | + assertThat(game.getAge(), is(1)); |
| 69 | + |
| 70 | + // Next turn is 50AD |
| 71 | + game.endOfTurn(); |
| 72 | + assertThat(game.getAge(), is(50)); |
| 73 | + |
| 74 | + |
| 75 | + // 50 years per turn until 1750 |
| 76 | + for (int j = 0; j < 34; j++) { |
| 77 | + game.endOfTurn(); |
| 78 | + } |
| 79 | + assertThat(game.getAge(), is(1750)); |
| 80 | + |
| 81 | + // 25 years per turn until 1900 |
| 82 | + for (int h = 0; h < 6; h++) { |
| 83 | + game.endOfTurn(); |
| 84 | + } |
| 85 | + assertThat(game.getAge(), is(1900)); |
| 86 | + |
| 87 | + // 5 years per turn until 1970 |
| 88 | + for (int k = 0; k < 14; k++) { |
| 89 | + game.endOfTurn(); |
| 90 | + } |
| 91 | + assertThat(game.getAge(), is(1970)); |
| 92 | + |
| 93 | + // 1 year per turn for the rest of the game |
| 94 | + for (int m = 0; m < 100; m++) { |
| 95 | + game.endOfTurn(); |
| 96 | + } |
| 97 | + assertThat(game.getAge(), is(2070)); |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + @Test |
| 102 | + public void betaCiv_FirstPlayerThatConquersWorldWins() { |
| 103 | + Position city1 = new Position(1, 1); |
| 104 | + Position city2 = new Position(1, 4); |
| 105 | + |
| 106 | + game.setCityAt(city1, Player.BLUE); |
| 107 | + |
| 108 | + assertThat(game.getCityAt(city1).getOwner(), is(Player.BLUE)); |
| 109 | + |
| 110 | + assertThat(game.getWinner(), is(Player.BLUE)); // Blue owns both cities and should win |
| 111 | + |
| 112 | + game.setCityAt(city1, Player.RED); |
| 113 | + game.setCityAt(city2, Player.RED); |
| 114 | + |
| 115 | + assertThat(game.getWinner(), is(Player.BLUE)); // Blue already won the game, so they remain the winner. |
| 116 | + } |
| 117 | +} |
| 118 | + |
0 commit comments