quoridor/src/test/java/cz/xelfi/quoridor/SerializeCodeTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 181 e3fb438103e0
permissions -rw-r--r--
Changing headers to GPLv3
jaroslav@181
     1
/*
jaroslav@264
     2
 * Quoridor server and related libraries
jaroslav@264
     3
 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@181
     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@181
     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@181
    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@181
    17
 */
jaroslav@181
    18
package cz.xelfi.quoridor;
jaroslav@181
    19
jaroslav@181
    20
import cz.xelfi.quoridor.Player.Direction;
jaroslav@181
    21
import java.io.IOException;
jaroslav@181
    22
jaroslav@181
    23
/** Basic tests in simple configuration.
jaroslav@181
    24
 *
jaroslav@181
    25
 * @author Jaroslav Tulach
jaroslav@181
    26
 */
jaroslav@181
    27
public class SerializeCodeTest extends BoardCase {
jaroslav@181
    28
    public SerializeCodeTest (String testName) {
jaroslav@181
    29
        super (testName);
jaroslav@181
    30
    }
jaroslav@181
    31
jaroslav@181
    32
    @Override
jaroslav@181
    33
    protected Board move(Board b, int player, Direction... where) throws IllegalPositionException {
jaroslav@181
    34
        try {
jaroslav@181
    35
            Board read = reread(b);
jaroslav@181
    36
            return read.move(read.getPlayers().get(player), where);
jaroslav@181
    37
        } catch (IOException ex) {
jaroslav@181
    38
            throw new IllegalStateException(ex);
jaroslav@181
    39
        }
jaroslav@181
    40
    }
jaroslav@181
    41
    protected Board fence(Board b, int player, char x, int y, Fence.Orientation orie)
jaroslav@181
    42
    throws IllegalPositionException {
jaroslav@181
    43
        try {
jaroslav@181
    44
            Board read = reread(b);
jaroslav@181
    45
            return read.fence(read.getPlayers().get(player), x, y, orie);
jaroslav@181
    46
        } catch (IOException ex) {
jaroslav@181
    47
            throw new IllegalStateException(ex);
jaroslav@181
    48
        }
jaroslav@181
    49
    }
jaroslav@181
    50
jaroslav@181
    51
    @Override
jaroslav@181
    52
    protected Board apply(Board b, Move move) throws IllegalPositionException {
jaroslav@181
    53
        try {
jaroslav@181
    54
            Board read = reread(b);
jaroslav@181
    55
            return read.apply(move);
jaroslav@181
    56
        } catch (IOException ex) {
jaroslav@181
    57
            throw new IllegalStateException(ex);
jaroslav@181
    58
        }
jaroslav@181
    59
    }
jaroslav@181
    60
jaroslav@181
    61
    private Board reread(Board b) throws IOException, IllegalPositionException {
jaroslav@181
    62
        return Board.valueOf(b.getCode());
jaroslav@181
    63
    }
jaroslav@181
    64
jaroslav@181
    65
}