Initial version of statistics and ELO rating. Donated by Martin Rexa
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * The contents of this file are subject to the terms of either the GNU
5 * General Public License Version 2 only ("GPL") or the Common
6 * Development and Distribution License("CDDL") (collectively, the
7 * "License"). You may not use this file except in compliance with the
8 * License. You can obtain a copy of the License at
9 * http://www.netbeans.org/cddl-gplv2.html
10 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11 * specific language governing permissions and limitations under the
12 * License. When distributing the software, include this License Header
13 * Notice in each file and include the License file at
14 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
15 * particular file as subject to the "Classpath" exception as provided
16 * by Sun in the GPL Version 2 section of the License file that
17 * accompanied this code. If applicable, add the following below the
18 * License Header, with the fields enclosed by brackets [] replaced by
19 * your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Portions Copyrighted 2010 Martin Rexa
27 package cz.xelfi.quoridor.statistics;
29 import cz.xelfi.quoridor.Fence.Orientation;
30 import org.junit.Test;
31 import static org.junit.Assert.*;
32 import cz.xelfi.quoridor.Move;
33 import cz.xelfi.quoridor.webidor.Game;
40 public class OpeningsTest extends Object {
42 public OpeningsTest() throws Exception {
45 @Test public void testMirrorMoves() throws Exception {
46 assertEquals("bad symetric move", Move.NORTH.getMirrorMove(), Move.NORTH);
47 assertEquals("bad symetric move", Move.SOUTH.getMirrorMove(), Move.SOUTH);
48 assertEquals("bad symetric move", Move.WEST.getMirrorMove(), Move.EAST);
49 assertEquals("bad symetric move", Move.EAST.getMirrorMove(), Move.WEST);
50 assertEquals("bad symetric move", Move.fence('A', 1, Orientation.HORIZONTAL).getMirrorMove(), Move.fence('H', 1, Orientation.HORIZONTAL));
51 assertEquals("bad symetric move", Move.fence('D', 3, Orientation.VERTICAL).getMirrorMove(), Move.fence('E', 3, Orientation.VERTICAL));
54 @Test public void testMirrorJump() throws Exception {
55 Game g = new Game("w","b");
56 g.apply("w", Move.NORTH, new java.util.Date());
57 g.apply("b", Move.SOUTH, new java.util.Date());
58 g.apply("w", Move.NORTH, new java.util.Date());
59 g.apply("b", Move.SOUTH, new java.util.Date());
60 g.apply("w", Move.NORTH, new java.util.Date());
61 g.apply("b", Move.SOUTH, new java.util.Date());
62 g.apply("w", Move.NORTH, new java.util.Date());
63 g.apply("b", Move.EAST, new java.util.Date());
64 g.apply("w", Move.NORTH, new java.util.Date());
65 g.apply("b", Move.valueOf("WW"), new java.util.Date());
66 g.apply("w", Move.RESIGN, new java.util.Date());
67 OpeningTree t = new OpeningTree();
69 OpeningTreeNode n = t.root;
70 n = n.children.get(Move.NORTH);
71 n = n.children.get(Move.SOUTH);
72 n = n.children.get(Move.NORTH);
73 n = n.children.get(Move.SOUTH);
74 n = n.children.get(Move.NORTH);
75 n = n.children.get(Move.SOUTH);
76 n = n.children.get(Move.NORTH);
77 n = n.children.get(Move.WEST);
78 n = n.children.get(Move.NORTH);
79 n = n.children.get(Move.valueOf("EE"));
80 assertEquals("bad number of children", n.children.size(), 0);
81 for(Map.Entry e: n.children.entrySet()){
82 System.out.println(e.getKey());
86 @Test public void testOpeningTreeNodes() throws Exception {
87 OpeningTree t = new OpeningTree();
88 assertEquals("bad number of nodes", t.nodes.size(), 1);
89 Game g = new Game("w","b");
90 g.apply("w", Move.NORTH, new java.util.Date());
91 g.apply("b", Move.SOUTH, new java.util.Date());
92 g.apply("w", Move.EAST, new java.util.Date());
93 g.apply("b", Move.EAST, new java.util.Date());
94 g.apply("w", Move.WEST, new java.util.Date());
95 g.apply("b", Move.WEST, new java.util.Date());
96 g.apply("w", Move.RESIGN, new java.util.Date());
98 assertEquals("bad number of nodes", t.nodes.size(), 9);
99 g = new Game("w","b");
100 g.apply("w", Move.NORTH, new java.util.Date());
101 g.apply("b", Move.SOUTH, new java.util.Date());
102 g.apply("w", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
103 g.apply("b", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
104 g.apply("w", Move.RESIGN, new java.util.Date());
106 assertEquals("bad number of nodes", t.nodes.size(), 13);
107 g = new Game("w","b");
108 g.apply("w", Move.NORTH, new java.util.Date());
109 g.apply("b", Move.SOUTH, new java.util.Date());
110 g.apply("w", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
111 g.apply("b", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
112 g.apply("w", Move.RESIGN, new java.util.Date());
114 assertEquals("bad number of nodes", t.nodes.size(), 15);
115 OpeningTreeNode n = t.root;
116 n = n.children.get(Move.NORTH);
117 n = n.children.get(Move.SOUTH);
118 OpeningTreeNode n1 = n;
119 n = n.children.get(Move.WEST);
120 n = n.children.get(Move.WEST);
121 n = n.children.get(Move.EAST);
122 n = n.children.get(Move.EAST);
123 assertEquals("different nodes", n.hashCode, n1.hashCode);
124 n = n.children.get(Move.fence('F', 1, Orientation.VERTICAL));
125 n = n.children.get(Move.fence('H', 1, Orientation.HORIZONTAL));
126 assertEquals("bad number of children", n.children.size(), 0);