statistics/src/test/java/cz/xelfi/quoridor/statistics/OpeningsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 09:46:43 +0200
changeset 266 15fcdfc4cd4a
parent 264 d60370059c3c
permissions -rw-r--r--
Using maven-license-plugin and updating all missing headers
     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 
    19 package cz.xelfi.quoridor.statistics;
    20 
    21 import cz.xelfi.quoridor.Fence.Orientation;
    22 import org.junit.Test;
    23 import static org.junit.Assert.*;
    24 import cz.xelfi.quoridor.Move;
    25 import cz.xelfi.quoridor.webidor.Game;
    26 import java.util.Map;
    27 
    28 /**
    29  *
    30  * @author Martin Rexa
    31  */
    32 public class OpeningsTest extends Object {
    33     
    34     public OpeningsTest() throws Exception {
    35     }
    36 
    37     @Test public void testMirrorMoves() throws Exception {
    38         assertEquals("bad symetric move", Move.NORTH.getMirrorMove(), Move.NORTH);
    39         assertEquals("bad symetric move", Move.SOUTH.getMirrorMove(), Move.SOUTH);
    40         assertEquals("bad symetric move", Move.WEST.getMirrorMove(), Move.EAST);
    41         assertEquals("bad symetric move", Move.EAST.getMirrorMove(), Move.WEST);
    42         assertEquals("bad symetric move", Move.fence('A', 1, Orientation.HORIZONTAL).getMirrorMove(), Move.fence('H', 1, Orientation.HORIZONTAL));
    43         assertEquals("bad symetric move", Move.fence('D', 3, Orientation.VERTICAL).getMirrorMove(), Move.fence('E', 3, Orientation.VERTICAL));
    44     }
    45 
    46     @Test public void testMirrorJump() throws Exception {
    47         Game g = new Game("w","b");
    48         g.apply("w", Move.NORTH, new java.util.Date());
    49         g.apply("b", Move.SOUTH, new java.util.Date());
    50         g.apply("w", Move.NORTH, new java.util.Date());
    51         g.apply("b", Move.SOUTH, new java.util.Date());
    52         g.apply("w", Move.NORTH, new java.util.Date());
    53         g.apply("b", Move.SOUTH, new java.util.Date());
    54         g.apply("w", Move.NORTH, new java.util.Date());
    55         g.apply("b", Move.EAST, new java.util.Date());
    56         g.apply("w", Move.NORTH, new java.util.Date());
    57         g.apply("b", Move.valueOf("WW"), new java.util.Date());
    58         g.apply("w", Move.RESIGN, new java.util.Date());
    59         OpeningTree t = new OpeningTree();
    60         t.processGame(g);
    61         OpeningTreeNode n = t.root;
    62         n = n.children.get(Move.NORTH);
    63         n = n.children.get(Move.SOUTH);
    64         n = n.children.get(Move.NORTH);
    65         n = n.children.get(Move.SOUTH);
    66         n = n.children.get(Move.NORTH);
    67         n = n.children.get(Move.SOUTH);
    68         n = n.children.get(Move.NORTH);
    69         n = n.children.get(Move.WEST);
    70         n = n.children.get(Move.NORTH);
    71         n = n.children.get(Move.valueOf("EE"));
    72         assertEquals("bad number of children", n.children.size(), 0);
    73         for(Map.Entry e: n.children.entrySet()){
    74             System.out.println(e.getKey());
    75         }
    76     }
    77 
    78     @Test public void testOpeningTreeNodes() throws Exception {
    79         OpeningTree t = new OpeningTree();
    80         assertEquals("bad number of nodes", t.nodes.size(), 1);
    81         Game g = new Game("w","b");
    82         g.apply("w", Move.NORTH, new java.util.Date());
    83         g.apply("b", Move.SOUTH, new java.util.Date());
    84         g.apply("w", Move.EAST, new java.util.Date());
    85         g.apply("b", Move.EAST, new java.util.Date());
    86         g.apply("w", Move.WEST, new java.util.Date());
    87         g.apply("b", Move.WEST, new java.util.Date());
    88         g.apply("w", Move.RESIGN, new java.util.Date());
    89         t.processGame(g);
    90         assertEquals("bad number of nodes", t.nodes.size(), 9);
    91         g = new Game("w","b");
    92         g.apply("w", Move.NORTH, new java.util.Date());
    93         g.apply("b", Move.SOUTH, new java.util.Date());
    94         g.apply("w", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
    95         g.apply("b", Move.fence('C', 1, Orientation.VERTICAL), new java.util.Date());
    96         g.apply("w", Move.RESIGN, new java.util.Date());
    97         t.processGame(g);
    98         assertEquals("bad number of nodes", t.nodes.size(), 13);
    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('C', 1, Orientation.VERTICAL), new java.util.Date());
   103         g.apply("b", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
   104         g.apply("w", Move.RESIGN, new java.util.Date());
   105         t.processGame(g);
   106         assertEquals("bad number of nodes", t.nodes.size(), 15);
   107         OpeningTreeNode n = t.root;
   108         n = n.children.get(Move.NORTH);
   109         n = n.children.get(Move.SOUTH);
   110         OpeningTreeNode n1 = n;
   111         n = n.children.get(Move.WEST);
   112         n = n.children.get(Move.WEST);
   113         n = n.children.get(Move.EAST);
   114         n = n.children.get(Move.EAST);
   115         assertEquals("different nodes", n.hashCode, n1.hashCode);
   116         n = n.children.get(Move.fence('F', 1, Orientation.VERTICAL));
   117         n = n.children.get(Move.fence('H', 1, Orientation.HORIZONTAL));
   118         assertEquals("bad number of children", n.children.size(), 0);
   119     }
   120 
   121 }