quoridor/src/test/java/cz/xelfi/quoridor/MoveTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 75 6802034b7a6f
permissions -rw-r--r--
Changing headers to GPLv3
     1 /*
     2  * Quoridor server and related libraries
     3  * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     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;
    19 
    20 import cz.xelfi.quoridor.Fence.Orientation;
    21 import cz.xelfi.quoridor.Player.Direction;
    22 import org.junit.Test;
    23 import static org.junit.Assert.*;
    24 
    25 /**
    26  *
    27  * @author Jaroslav Tulach <jtulach@netbeans.org>
    28  */
    29 public class MoveTest {
    30 
    31     public MoveTest() {
    32     }
    33 
    34     @Test
    35     public void testNorth() throws Exception {
    36         checkValueOf("N", Move.NORTH);
    37     }
    38     @Test
    39     public void testSouth() throws Exception {
    40         checkValueOf("S", Move.SOUTH);
    41     }
    42     @Test
    43     public void testEast() throws Exception {
    44         checkValueOf("E", Move.EAST);
    45     }
    46     @Test
    47     public void testWest() throws Exception {
    48         checkValueOf("W", Move.WEST);
    49     }
    50     @Test
    51     public void testRegisn() throws Exception {
    52         checkValueOf("RESIGN", Move.RESIGN);
    53     }
    54     @Test
    55     public void testJumps() throws Exception {
    56         for (Direction d1 : Direction.values()) {
    57             for (Direction d2 : Direction.values()) {
    58                 checkValueOf("" + d1.name().charAt(0) + d2.name().charAt(0), Move.jump(d1, d2));
    59             }
    60         }
    61     }
    62     @Test
    63     public void testFences() throws Exception {
    64         for (int i = 1; i <= 8; i++) {
    65             for (int j = 0; i < 8; i++) {
    66                 String h = "H" + (char)('A'+ j) + i;
    67                 String v = "V" + (char)('A'+ j) + i;
    68 
    69                 Move hm = Move.fence((char) ('A' + j), i, Orientation.HORIZONTAL);
    70                 Move vm = Move.fence((char) ('A' + j), i, Orientation.VERTICAL);
    71 
    72                 checkValueOf(h, hm);
    73                 checkValueOf(v, vm);
    74             }
    75         }
    76     }
    77 
    78     private static void checkValueOf(String txt, Move move) throws Exception {
    79         assertEquals("toString", txt, move.toString());
    80         assertEquals("valueOf", move, Move.valueOf(txt));
    81     }
    82 
    83 }