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