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
jaroslav@266
     1
/**
jaroslav@264
     2
 * Quoridor server and related libraries
jaroslav@264
     3
 * Copyright (C) 2009-2010 Martin Rexa
jaroslav@178
     4
 *
jaroslav@264
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@264
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@264
     7
 * the Free Software Foundation, either version 3 of the License.
jaroslav@178
     8
 *
jaroslav@264
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@264
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@264
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@264
    12
 * GNU General Public License for more details.
jaroslav@178
    13
 *
jaroslav@264
    14
 * You should have received a copy of the GNU General Public License
jaroslav@264
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@264
    16
 * If not, see http://www.gnu.org/licenses/.
jaroslav@178
    17
 */
jaroslav@266
    18
jaroslav@178
    19
package cz.xelfi.quoridor.statistics;
jaroslav@178
    20
jaroslav@178
    21
import cz.xelfi.quoridor.Fence.Orientation;
jaroslav@178
    22
import org.junit.Test;
jaroslav@178
    23
import static org.junit.Assert.*;
jaroslav@178
    24
import cz.xelfi.quoridor.Move;
jaroslav@178
    25
import cz.xelfi.quoridor.webidor.Game;
jaroslav@178
    26
import java.util.Map;
jaroslav@178
    27
jaroslav@178
    28
/**
jaroslav@178
    29
 *
jaroslav@178
    30
 * @author Martin Rexa
jaroslav@178
    31
 */
jaroslav@178
    32
public class OpeningsTest extends Object {
jaroslav@178
    33
    
jaroslav@178
    34
    public OpeningsTest() throws Exception {
jaroslav@178
    35
    }
jaroslav@178
    36
jaroslav@178
    37
    @Test public void testMirrorMoves() throws Exception {
jaroslav@178
    38
        assertEquals("bad symetric move", Move.NORTH.getMirrorMove(), Move.NORTH);
jaroslav@178
    39
        assertEquals("bad symetric move", Move.SOUTH.getMirrorMove(), Move.SOUTH);
jaroslav@178
    40
        assertEquals("bad symetric move", Move.WEST.getMirrorMove(), Move.EAST);
jaroslav@178
    41
        assertEquals("bad symetric move", Move.EAST.getMirrorMove(), Move.WEST);
jaroslav@178
    42
        assertEquals("bad symetric move", Move.fence('A', 1, Orientation.HORIZONTAL).getMirrorMove(), Move.fence('H', 1, Orientation.HORIZONTAL));
jaroslav@178
    43
        assertEquals("bad symetric move", Move.fence('D', 3, Orientation.VERTICAL).getMirrorMove(), Move.fence('E', 3, Orientation.VERTICAL));
jaroslav@178
    44
    }
jaroslav@178
    45
jaroslav@178
    46
    @Test public void testMirrorJump() throws Exception {
jaroslav@178
    47
        Game g = new Game("w","b");
jaroslav@178
    48
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    49
        g.apply("b", Move.SOUTH, new java.util.Date());
jaroslav@178
    50
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    51
        g.apply("b", Move.SOUTH, new java.util.Date());
jaroslav@178
    52
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    53
        g.apply("b", Move.SOUTH, new java.util.Date());
jaroslav@178
    54
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    55
        g.apply("b", Move.EAST, new java.util.Date());
jaroslav@178
    56
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    57
        g.apply("b", Move.valueOf("WW"), new java.util.Date());
jaroslav@178
    58
        g.apply("w", Move.RESIGN, new java.util.Date());
jaroslav@178
    59
        OpeningTree t = new OpeningTree();
jaroslav@178
    60
        t.processGame(g);
jaroslav@178
    61
        OpeningTreeNode n = t.root;
jaroslav@178
    62
        n = n.children.get(Move.NORTH);
jaroslav@178
    63
        n = n.children.get(Move.SOUTH);
jaroslav@178
    64
        n = n.children.get(Move.NORTH);
jaroslav@178
    65
        n = n.children.get(Move.SOUTH);
jaroslav@178
    66
        n = n.children.get(Move.NORTH);
jaroslav@178
    67
        n = n.children.get(Move.SOUTH);
jaroslav@178
    68
        n = n.children.get(Move.NORTH);
jaroslav@178
    69
        n = n.children.get(Move.WEST);
jaroslav@178
    70
        n = n.children.get(Move.NORTH);
jaroslav@178
    71
        n = n.children.get(Move.valueOf("EE"));
jaroslav@178
    72
        assertEquals("bad number of children", n.children.size(), 0);
jaroslav@178
    73
        for(Map.Entry e: n.children.entrySet()){
jaroslav@178
    74
            System.out.println(e.getKey());
jaroslav@178
    75
        }
jaroslav@178
    76
    }
jaroslav@178
    77
jaroslav@178
    78
    @Test public void testOpeningTreeNodes() throws Exception {
jaroslav@178
    79
        OpeningTree t = new OpeningTree();
jaroslav@178
    80
        assertEquals("bad number of nodes", t.nodes.size(), 1);
jaroslav@178
    81
        Game g = new Game("w","b");
jaroslav@178
    82
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    83
        g.apply("b", Move.SOUTH, new java.util.Date());
jaroslav@178
    84
        g.apply("w", Move.EAST, new java.util.Date());
jaroslav@178
    85
        g.apply("b", Move.EAST, new java.util.Date());
jaroslav@178
    86
        g.apply("w", Move.WEST, new java.util.Date());
jaroslav@178
    87
        g.apply("b", Move.WEST, new java.util.Date());
jaroslav@178
    88
        g.apply("w", Move.RESIGN, new java.util.Date());
jaroslav@178
    89
        t.processGame(g);
jaroslav@178
    90
        assertEquals("bad number of nodes", t.nodes.size(), 9);
jaroslav@178
    91
        g = new Game("w","b");
jaroslav@178
    92
        g.apply("w", Move.NORTH, new java.util.Date());
jaroslav@178
    93
        g.apply("b", Move.SOUTH, new java.util.Date());
jaroslav@178
    94
        g.apply("w", Move.fence('A', 1, Orientation.HORIZONTAL), new java.util.Date());
jaroslav@178
    95
        g.apply("b", Move.fence('C', 1, Orientation.VERTICAL), 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(), 13);
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('C', 1, Orientation.VERTICAL), new java.util.Date());
jaroslav@178
   103
        g.apply("b", Move.fence('A', 1, Orientation.HORIZONTAL), 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(), 15);
jaroslav@178
   107
        OpeningTreeNode n = t.root;
jaroslav@178
   108
        n = n.children.get(Move.NORTH);
jaroslav@178
   109
        n = n.children.get(Move.SOUTH);
jaroslav@178
   110
        OpeningTreeNode n1 = n;
jaroslav@178
   111
        n = n.children.get(Move.WEST);
jaroslav@178
   112
        n = n.children.get(Move.WEST);
jaroslav@178
   113
        n = n.children.get(Move.EAST);
jaroslav@178
   114
        n = n.children.get(Move.EAST);
jaroslav@178
   115
        assertEquals("different nodes", n.hashCode, n1.hashCode);
jaroslav@178
   116
        n = n.children.get(Move.fence('F', 1, Orientation.VERTICAL));
jaroslav@178
   117
        n = n.children.get(Move.fence('H', 1, Orientation.HORIZONTAL));
jaroslav@178
   118
        assertEquals("bad number of children", n.children.size(), 0);
jaroslav@178
   119
    }
jaroslav@178
   120
jaroslav@178
   121
}