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