[gnome-games/glchess-vala] Add a test program
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/glchess-vala] Add a test program
- Date: Mon, 27 Dec 2010 02:31:14 +0000 (UTC)
commit 09b873ec4911089d12a7bc74f0f70f89fd342067
Author: Robert Ancell <robert ancell canonical com>
Date: Mon Dec 27 13:31:07 2010 +1100
Add a test program
configure.in | 4 +++
glchess/src/Makefile.am | 17 +++++++++++-
glchess/src/chess-game.vala | 2 +-
glchess/src/chess-pgn.vala | 7 ++++-
glchess/src/test-chess-game.vala | 55 ++++++++++++++++++++++++++++++++++++++
5 files changed, 82 insertions(+), 3 deletions(-)
---
diff --git a/configure.in b/configure.in
index c26c9c0..15a4b88 100644
--- a/configure.in
+++ b/configure.in
@@ -623,6 +623,10 @@ PKG_CHECK_MODULES([GMODULE],[gmodule-2.0])
AC_SUBST([GMODULE_CFLAGS])
AC_SUBST([GMODULE_LIBS])
+PKG_CHECK_MODULES([GOBJECT],[gobject-2.0])
+AC_SUBST([GOBJECT_CFLAGS])
+AC_SUBST([GOBJECT_LIBS])
+
PKG_CHECK_MODULES([GTK],[gtk+-$GTK_API_VERSION >= $GTK_REQUIRED])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
diff --git a/glchess/src/Makefile.am b/glchess/src/Makefile.am
index eeabd96..0c5b520 100644
--- a/glchess/src/Makefile.am
+++ b/glchess/src/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = glchess
+bin_PROGRAMS = glchess test-chess-game
glchess_SOURCES = \
3ds.vala \
@@ -15,6 +15,21 @@ glchess_SOURCES = \
chess-view-3d.vala \
chess-view-options.vala
+test_chess_game_SOURCES = \
+ chess-bitboard.vala \
+ chess-game.vala \
+ test-chess-game.vala
+
+test_chess_game_CFLAGS = \
+ $(GOBJECT_CFLAGS)
+
+test_chess_game_LDADD = \
+ $(GOBJECT_LIBS)
+
+test_chess_game_VALAFLAGS = \
+ --pkg gobject-2.0 \
+ --pkg posix
+
glchess_CFLAGS = \
-DPKGDATADIR=\"@datadir@/glchess\" \
$(GMODULE_CFLAGS) \
diff --git a/glchess/src/chess-game.vala b/glchess/src/chess-game.vala
index 548b399..dd0c250 100644
--- a/glchess/src/chess-game.vala
+++ b/glchess/src/chess-game.vala
@@ -328,7 +328,7 @@ public class ChessState
// FIXME: Can only castle if:
// King hasn't moved
// Rook hasn't moved
- // Can't be in check while king moved (check if rook can be taken?)
+ // Can't be in check before, during or after move (check if rook can be taken?)
}
break;
default:
diff --git a/glchess/src/chess-pgn.vala b/glchess/src/chess-pgn.vala
index 197bcf9..f8dc29c 100644
--- a/glchess/src/chess-pgn.vala
+++ b/glchess/src/chess-pgn.vala
@@ -70,6 +70,11 @@ public class PGNGame
get { return tags.lookup ("Result"); }
set { tags.insert ("Result", value); }
}
+ public string? annotator
+ {
+ get { return tags.lookup ("Annotator"); }
+ set { tags.insert ("Annotator", value); }
+ }
public bool set_up
{
get { string? v = tags.lookup ("SetUp"); return v != null && v == "1" ? true : false; }
@@ -78,7 +83,7 @@ public class PGNGame
public string? fen
{
get { return tags.lookup ("FEN"); }
- set { tags.insert ("FEN", value); }
+ set { tags.insert ("FEN", value); }
}
public string? termination
{
diff --git a/glchess/src/test-chess-game.vala b/glchess/src/test-chess-game.vala
new file mode 100644
index 0000000..1360616
--- /dev/null
+++ b/glchess/src/test-chess-game.vala
@@ -0,0 +1,55 @@
+class GlChess
+{
+ static int test_count = 0;
+ static int failure_count = 0;
+
+ private static void test_good_move (string fen, string move)
+ {
+ ChessState state = new ChessState (fen);
+ if (!state.move (move, false))
+ {
+ stderr.printf ("Not allowed to do valid move: %s : %s\n", fen, move);
+ failure_count++;
+ }
+ test_count++;
+ }
+
+ private static void test_bad_move (string fen, string move)
+ {
+ ChessState state = new ChessState (fen);
+ if (state.move (move, false))
+ {
+ stderr.printf ("Allowed to do invalid move: %s : %s\n", fen, move);
+ failure_count++;
+ }
+ test_count++;
+ }
+
+ public static int main (string[] args)
+ {
+ /* Pawn move */
+ test_good_move ("8/8/8/8/8/8/P7/8 w KQkr - 0 1", "a2a3");
+
+ /* Pawn march */
+ test_good_move ("8/8/8/8/8/8/P7/8 w KQkr - 0 1", "a2a4");
+
+ /* Pawn march only allowed from baseline */
+ test_bad_move ("8/8/8/8/8/P7/8/8 w KQkr - 0 1", "a2a5");
+
+ /* Castle kingside */
+ test_good_move ("8/8/8/8/8/8/8/4K2R w KQkr - 0 1", "Kg1");
+
+ /* Can't castle when in check */
+ test_bad_move ("4r3/8/8/8/8/8/8/4K2R w KQkr - 0 1", "Kg1");
+
+ /* Can't move across square that would put into check */
+ test_bad_move ("5r2/8/8/8/8/8/8/4K2R w KQkr - 0 1", "Kg1");
+
+ /* Can't move into check */
+ test_bad_move ("4r3/8/8/8/8/8/4R3/4K3 w KQkr - 0 1", "e2f2");
+
+ stdout.printf ("%d/%d tests successful\n", test_count - failure_count, test_count);
+
+ return failure_count;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]