1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/statistics/src/test/java/cz/xelfi/quoridor/statistics/OpeningsTest.java Thu Jan 07 22:34:17 2010 +0100
1.3 @@ -0,0 +1,129 @@
1.4 +/*
1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 + *
1.7 + * The contents of this file are subject to the terms of either the GNU
1.8 + * General Public License Version 2 only ("GPL") or the Common
1.9 + * Development and Distribution License("CDDL") (collectively, the
1.10 + * "License"). You may not use this file except in compliance with the
1.11 + * License. You can obtain a copy of the License at
1.12 + * http://www.netbeans.org/cddl-gplv2.html
1.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.14 + * specific language governing permissions and limitations under the
1.15 + * License. When distributing the software, include this License Header
1.16 + * Notice in each file and include the License file at
1.17 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
1.18 + * particular file as subject to the "Classpath" exception as provided
1.19 + * by Sun in the GPL Version 2 section of the License file that
1.20 + * accompanied this code. If applicable, add the following below the
1.21 + * License Header, with the fields enclosed by brackets [] replaced by
1.22 + * your own identifying information:
1.23 + * "Portions Copyrighted [year] [name of copyright owner]"
1.24 + *
1.25 + * Contributor(s):
1.26 + *
1.27 + * Portions Copyrighted 2010 Martin Rexa
1.28 + */
1.29 +
1.30 +package cz.xelfi.quoridor.statistics;
1.31 +
1.32 +import cz.xelfi.quoridor.Fence.Orientation;
1.33 +import org.junit.Test;
1.34 +import static org.junit.Assert.*;
1.35 +import cz.xelfi.quoridor.Move;
1.36 +import cz.xelfi.quoridor.webidor.Game;
1.37 +import java.util.Map;
1.38 +
1.39 +/**
1.40 + *
1.41 + * @author Martin Rexa
1.42 + */
1.43 +public class OpeningsTest extends Object {
1.44 +
1.45 + public OpeningsTest() throws Exception {
1.46 + }
1.47 +
1.48 + @Test public void testMirrorMoves() throws Exception {
1.49 + assertEquals("bad symetric move", Move.NORTH.getMirrorMove(), Move.NORTH);
1.50 + assertEquals("bad symetric move", Move.SOUTH.getMirrorMove(), Move.SOUTH);
1.51 + assertEquals("bad symetric move", Move.WEST.getMirrorMove(), Move.EAST);
1.52 + assertEquals("bad symetric move", Move.EAST.getMirrorMove(), Move.WEST);
1.53 + assertEquals("bad symetric move", Move.fence('A', 1, Orientation.HORIZONTAL).getMirrorMove(), Move.fence('H', 1, Orientation.HORIZONTAL));
1.54 + assertEquals("bad symetric move", Move.fence('D', 3, Orientation.VERTICAL).getMirrorMove(), Move.fence('E', 3, Orientation.VERTICAL));
1.55 + }
1.56 +
1.57 + @Test public void testMirrorJump() throws Exception {
1.58 + Game g = new Game("w","b");
1.59 + g.apply("w", Move.NORTH, new java.util.Date());
1.60 + g.apply("b", Move.SOUTH, new java.util.Date());
1.61 + g.apply("w", Move.NORTH, new java.util.Date());
1.62 + g.apply("b", Move.SOUTH, new java.util.Date());
1.63 + g.apply("w", Move.NORTH, new java.util.Date());
1.64 + g.apply("b", Move.SOUTH, new java.util.Date());
1.65 + g.apply("w", Move.NORTH, new java.util.Date());
1.66 + g.apply("b", Move.EAST, new java.util.Date());
1.67 + g.apply("w", Move.NORTH, new java.util.Date());
1.68 + g.apply("b", Move.valueOf("WW"), new java.util.Date());
1.69 + g.apply("w", Move.RESIGN, new java.util.Date());
1.70 + OpeningTree t = new OpeningTree();
1.71 + t.processGame(g);
1.72 + OpeningTreeNode n = t.root;
1.73 + n = n.children.get(Move.NORTH);
1.74 + n = n.children.get(Move.SOUTH);
1.75 + n = n.children.get(Move.NORTH);
1.76 + n = n.children.get(Move.SOUTH);
1.77 + n = n.children.get(Move.NORTH);
1.78 + n = n.children.get(Move.SOUTH);
1.79 + n = n.children.get(Move.NORTH);
1.80 + n = n.children.get(Move.WEST);
1.81 + n = n.children.get(Move.NORTH);
1.82 + n = n.children.get(Move.valueOf("EE"));
1.83 + assertEquals("bad number of children", n.children.size(), 0);
1.84 + for(Map.Entry e: n.children.entrySet()){
1.85 + System.out.println(e.getKey());
1.86 + }
1.87 + }
1.88 +
1.89 + @Test public void testOpeningTreeNodes() throws Exception {
1.90 + OpeningTree t = new OpeningTree();
1.91 + assertEquals("bad number of nodes", t.nodes.size(), 1);
1.92 + Game g = new Game("w","b");
1.93 + g.apply("w", Move.NORTH, new java.util.Date());
1.94 + g.apply("b", Move.SOUTH, new java.util.Date());
1.95 + g.apply("w", Move.EAST, new java.util.Date());
1.96 + g.apply("b", Move.EAST, new java.util.Date());
1.97 + g.apply("w", Move.WEST, new java.util.Date());
1.98 + g.apply("b", Move.WEST, new java.util.Date());
1.99 + g.apply("w", Move.RESIGN, new java.util.Date());
1.100 + t.processGame(g);
1.101 + assertEquals("bad number of nodes", t.nodes.size(), 9);
1.102 + g = new Game("w","b");
1.103 + g.apply("w", Move.NORTH, new java.util.Date());
1.104 + g.apply("b", Move.SOUTH, new java.util.Date());
1.105 + g.apply("w", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
1.106 + g.apply("b", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
1.107 + g.apply("w", Move.RESIGN, new java.util.Date());
1.108 + t.processGame(g);
1.109 + assertEquals("bad number of nodes", t.nodes.size(), 13);
1.110 + g = new Game("w","b");
1.111 + g.apply("w", Move.NORTH, new java.util.Date());
1.112 + g.apply("b", Move.SOUTH, new java.util.Date());
1.113 + g.apply("w", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
1.114 + g.apply("b", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
1.115 + g.apply("w", Move.RESIGN, new java.util.Date());
1.116 + t.processGame(g);
1.117 + assertEquals("bad number of nodes", t.nodes.size(), 15);
1.118 + OpeningTreeNode n = t.root;
1.119 + n = n.children.get(Move.NORTH);
1.120 + n = n.children.get(Move.SOUTH);
1.121 + OpeningTreeNode n1 = n;
1.122 + n = n.children.get(Move.WEST);
1.123 + n = n.children.get(Move.WEST);
1.124 + n = n.children.get(Move.EAST);
1.125 + n = n.children.get(Move.EAST);
1.126 + assertEquals("different nodes", n.hashCode, n1.hashCode);
1.127 + n = n.children.get(Move.fence('F', 1, Orientation.VERTICAL));
1.128 + n = n.children.get(Move.fence('H', 1, Orientation.HORIZONTAL));
1.129 + assertEquals("bad number of children", n.children.size(), 0);
1.130 + }
1.131 +
1.132 +}