2 // Copyright (c) 2013 Motoyuki Kasahara
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package jp.sourceforge.gamerandomizerlib;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Random;
22 import junit.framework.*;
23 import junit.textui.TestRunner;
24 import nedragtna.random.MTRandom;
26 public final class GameTest extends TestCase {
27 public GameTest(String name) {
34 public void testCostructor() {
36 String id = "test-game-id";
37 String title = "test-game-title";
38 int selectionSize = 10;
40 Game g = new Game(id, title, selectionSize);
42 assertEquals(g.getId(), id);
43 assertEquals(g.getTitle(), title);
44 assertEquals(g.getSelectionSize(), selectionSize);
45 } catch (Exception e) {
53 public void testCopyCostructor() {
55 String id = "test-game-id";
56 String title = "test-game-title";
57 int selectionSize = 10;
59 Game g1 = new Game(id, title, selectionSize);
60 Game g2 = new Game(g1);
62 assertEquals(g2.getId(), id);
63 assertEquals(g2.getTitle(), title);
64 assertEquals(g2.getSelectionSize(), selectionSize);
65 } catch (Exception e) {
71 // Test getId(), getTitle() and getSelectionSize().
73 public void testBasicGetters() {
75 String id = "test-game-id";
76 String title = "test-game-title";
77 int selectionSize = 10;
80 Game[] games = new Game[gamesSize];
81 for (int i = 0; i < gamesSize; i++)
82 games[i] = new Game(id + i, title + i, selectionSize + i);
84 for (int i = 0; i < gamesSize; i++) {
85 assertEquals(games[i].getId(), id + i);
86 assertEquals(games[i].getTitle(), title + i);
87 assertEquals(games[i].getSelectionSize(), selectionSize + i);
89 } catch (Exception e) {
97 public void testClear() {
99 Game g = new Game("test-game-id", "", 10);
100 Expansion x1 = new Expansion("test-expansion-id1", "", 1000);
101 Expansion x2 = new Expansion("test-expansion-id2", "", 1010);
104 g.addCard(new Card("test-card-id1", "", "", x1));
105 g.addCard(new Card("test-card-id1", "", "", x2)); // duplicate
106 g.addCard(new Card("test-card-id2", "", "", x2));
107 g.addCard(new Card("test-card-id3", "", "", x2));
108 assertTrue(g.getExpansions().size() > 0);
109 assertTrue(g.getCards().size() > 0);
113 assertTrue(g.getExpansions().size() == 0);
114 assertTrue(g.getCards().size() == 0);
117 // Check if duplicate cards are also removed by clear().
119 g.addCard(new Card("test-card-id1", "", "", x1));
120 g.removeCard(new Card("test-card-id1", "", "", x1));
122 assertTrue(g.getCards().size() == 0);
123 } catch (Exception e) {
124 fail(e.getMessage());
129 // Compare 'List<Expansion>' and 'Expansion ...expansions'.
131 public boolean compareExpansions(List<Expansion> list,
132 Expansion ...expansions) {
134 for (Expansion x : expansions) {
135 if (list.size() >= i || !x.equals(list.get(i)))
143 // Compare 'List<Card>' and 'Card ...cards'.
145 public boolean compareCards(List<Card> list, Card ...cards) {
147 for (Card c : cards) {
148 if (list.size() >= i || !c.equals(list.get(i)))
156 // Test addExpansion().
158 public void testAddExpansion() {
160 Game g = new Game("test-game-id", "", 10);
162 Expansion x1 = new Expansion("test-expansion-id1", "", 1010);
163 assertTrue(g.addExpansion(x1));
164 compareExpansions(g.getExpansions(), x1);
166 Expansion x2 = new Expansion("test-expansion-id2", "", 1020);
167 assertTrue(g.addExpansion(x2));
168 compareExpansions(g.getExpansions(), x1, x2);
170 Expansion x3 = new Expansion("test-expansion-id3", "", 1000);
171 assertTrue(g.addExpansion(x3));
172 compareExpansions(g.getExpansions(), x3, x1, x2);
174 Expansion x4 = new Expansion("test-expansion-id3", "?", 1030);
175 assertFalse(g.addExpansion(x4));
176 compareExpansions(g.getExpansions(), x3, x1, x2);
177 } catch (Exception e) {
178 fail(e.getMessage());
183 // Test addExpansions().
185 public void testAddExpansions() {
187 Game g = new Game("test-game-id", "", 10);
189 List<Expansion> xl = new ArrayList<Expansion>();
190 Expansion x1 = new Expansion("test-expansion-id1", "", 1010);
191 Expansion x2 = new Expansion("test-expansion-id2", "", 1020);
192 Expansion x3 = new Expansion("test-expansion-id3", "", 1000);
194 assertTrue(g.addExpansion(x1));
195 compareExpansions(g.getExpansions(), x1);
197 assertTrue(g.addExpansion(x2));
198 compareExpansions(g.getExpansions(), x1, x2);
200 assertTrue(g.addExpansion(x3));
201 compareExpansions(g.getExpansions(), x3, x1, x2);
203 Expansion x4 = new Expansion("test-expansion-id3", "?", 1030);
204 assertFalse(g.addExpansion(x4));
205 compareExpansions(g.getExpansions(), x3, x1, x2);
206 } catch (Exception e) {
207 fail(e.getMessage());
214 public void testToString() {
216 String title = "test-game-title";
217 Game g = new Game("test-game-id", title, 10);
218 assertEquals(g.toString(), title);
219 } catch (Exception e) {
220 fail(e.getMessage());
224 public static void main(String[] args) {
225 junit.textui.TestRunner.run(GameTest.class);