2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Martin Rexa
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
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. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
18 package cz.xelfi.quoridor.statistics;
20 import cz.xelfi.quoridor.Fence.Orientation;
21 import org.junit.Test;
22 import static org.junit.Assert.*;
23 import cz.xelfi.quoridor.Move;
24 import cz.xelfi.quoridor.webidor.Game;
31 public class OpeningsTest extends Object {
33 public OpeningsTest() throws Exception {
36 @Test public void testMirrorMoves() throws Exception {
37 assertEquals("bad symetric move", Move.NORTH.getMirrorMove(), Move.NORTH);
38 assertEquals("bad symetric move", Move.SOUTH.getMirrorMove(), Move.SOUTH);
39 assertEquals("bad symetric move", Move.WEST.getMirrorMove(), Move.EAST);
40 assertEquals("bad symetric move", Move.EAST.getMirrorMove(), Move.WEST);
41 assertEquals("bad symetric move", Move.fence('A', 1, Orientation.HORIZONTAL).getMirrorMove(), Move.fence('H', 1, Orientation.HORIZONTAL));
42 assertEquals("bad symetric move", Move.fence('D', 3, Orientation.VERTICAL).getMirrorMove(), Move.fence('E', 3, Orientation.VERTICAL));
45 @Test public void testMirrorJump() throws Exception {
46 Game g = new Game("w","b");
47 g.apply("w", Move.NORTH, new java.util.Date());
48 g.apply("b", Move.SOUTH, new java.util.Date());
49 g.apply("w", Move.NORTH, new java.util.Date());
50 g.apply("b", Move.SOUTH, new java.util.Date());
51 g.apply("w", Move.NORTH, new java.util.Date());
52 g.apply("b", Move.SOUTH, new java.util.Date());
53 g.apply("w", Move.NORTH, new java.util.Date());
54 g.apply("b", Move.EAST, new java.util.Date());
55 g.apply("w", Move.NORTH, new java.util.Date());
56 g.apply("b", Move.valueOf("WW"), new java.util.Date());
57 g.apply("w", Move.RESIGN, new java.util.Date());
58 OpeningTree t = new OpeningTree();
60 OpeningTreeNode n = t.root;
61 n = n.children.get(Move.NORTH);
62 n = n.children.get(Move.SOUTH);
63 n = n.children.get(Move.NORTH);
64 n = n.children.get(Move.SOUTH);
65 n = n.children.get(Move.NORTH);
66 n = n.children.get(Move.SOUTH);
67 n = n.children.get(Move.NORTH);
68 n = n.children.get(Move.WEST);
69 n = n.children.get(Move.NORTH);
70 n = n.children.get(Move.valueOf("EE"));
71 assertEquals("bad number of children", n.children.size(), 0);
72 for(Map.Entry e: n.children.entrySet()){
73 System.out.println(e.getKey());
77 @Test public void testOpeningTreeNodes() throws Exception {
78 OpeningTree t = new OpeningTree();
79 assertEquals("bad number of nodes", t.nodes.size(), 1);
80 Game g = new Game("w","b");
81 g.apply("w", Move.NORTH, new java.util.Date());
82 g.apply("b", Move.SOUTH, new java.util.Date());
83 g.apply("w", Move.EAST, new java.util.Date());
84 g.apply("b", Move.EAST, new java.util.Date());
85 g.apply("w", Move.WEST, new java.util.Date());
86 g.apply("b", Move.WEST, new java.util.Date());
87 g.apply("w", Move.RESIGN, new java.util.Date());
89 assertEquals("bad number of nodes", t.nodes.size(), 9);
90 g = new Game("w","b");
91 g.apply("w", Move.NORTH, new java.util.Date());
92 g.apply("b", Move.SOUTH, new java.util.Date());
93 g.apply("w", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
94 g.apply("b", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
95 g.apply("w", Move.RESIGN, new java.util.Date());
97 assertEquals("bad number of nodes", t.nodes.size(), 13);
98 g = new Game("w","b");
99 g.apply("w", Move.NORTH, new java.util.Date());
100 g.apply("b", Move.SOUTH, new java.util.Date());
101 g.apply("w", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
102 g.apply("b", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
103 g.apply("w", Move.RESIGN, new java.util.Date());
105 assertEquals("bad number of nodes", t.nodes.size(), 15);
106 OpeningTreeNode n = t.root;
107 n = n.children.get(Move.NORTH);
108 n = n.children.get(Move.SOUTH);
109 OpeningTreeNode n1 = n;
110 n = n.children.get(Move.WEST);
111 n = n.children.get(Move.WEST);
112 n = n.children.get(Move.EAST);
113 n = n.children.get(Move.EAST);
114 assertEquals("different nodes", n.hashCode, n1.hashCode);
115 n = n.children.get(Move.fence('F', 1, Orientation.VERTICAL));
116 n = n.children.get(Move.fence('H', 1, Orientation.HORIZONTAL));
117 assertEquals("bad number of children", n.children.size(), 0);