statistics/src/test/java/cz/xelfi/quoridor/statistics/OpeningsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 178 4b78d4f028b3
child 266 15fcdfc4cd4a
permissions -rw-r--r--
Changing headers to GPLv3
     1 /*
     2  * Quoridor server and related libraries
     3  * Copyright (C) 2009-2010 Martin Rexa
     4  *
     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.
     8  *
     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.
    13  *
    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/.
    17  */
    18 package cz.xelfi.quoridor.statistics;
    19 
    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;
    25 import java.util.Map;
    26 
    27 /**
    28  *
    29  * @author Martin Rexa
    30  */
    31 public class OpeningsTest extends Object {
    32     
    33     public OpeningsTest() throws Exception {
    34     }
    35 
    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));
    43     }
    44 
    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();
    59         t.processGame(g);
    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());
    74         }
    75     }
    76 
    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());
    88         t.processGame(g);
    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());
    96         t.processGame(g);
    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());
   104         t.processGame(g);
   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);
   118     }
   119 
   120 }