Added:
trunk/jgogears/jgogears/CheckAllSGFFilesTest.java
Log:
New unit test to validate all the SGF files
Added: trunk/jgogears/jgogears/CheckAllSGFFilesTest.java
==============================================================================
--- (empty file)
+++ trunk/jgogears/jgogears/CheckAllSGFFilesTest.java Mon Mar 10
00:15:12 2008
@@ -0,0 +1,71 @@
+/**
+ *
+ */
+package jgogears;
+
+import java.io.*;
+import java.util.*;
+
+import junit.framework.TestCase;
+
+/**
+ * Class to check that all the sgf files are valid and well behaving.
+ *
+ * @author syeates
+ */
+public class CheckAllSGFFilesTest extends TestCase {
+
+ /**
+ * Loads a ton of SGF files and tests the resulting boards
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public void testLoadAllSGFfiles() throws IOException {
+ Stack<String> files = new Stack<String>();
+ files.push("sgf/2004-12");
+
+ while (files.size() > 0) {
+ String filename = files.pop();
+ File file = new File(filename);
+ System.err.println("examining \"" + filename + "\"");
+ if (file.exists()) {
+ if (!file.isDirectory()) {
+ // System.err.println("\"" + filename + "\" is not a
+ // directory, parsing as an SGF file");
+
+ Game game = Game.loadFromFile(file);
+ if (game.getSize() == 19) {
+ Iterator<Move> i = game.getMoves();
+ Move move = null;
+ BoardI board = new Board(game.getSize());
+ // System.err.println("board size is: \"" + goGame.getSize()
+ // + "\"");
+ while (i.hasNext()) {
+ move = i.next();
+ assertNotNull(move);
+ // System.err.print("move: \"" + move + "\"");
+ // assertTrue("" + board + "\n" +
+ // move.toString(),board.isLegalMove(move));
+ board = board.newBoard(move);
+ System.err.print(".");
+ }
+ System.err.println();
+ }
+
+ } else {
+ System.err.println("\"" + filename + "\" is a directory");
+ String[] children = file.list();
+ if (!file.getName().contains(".svn"))
+ for (int i = 0; i < children.length; i++) {
+ // System.err.println("pushing \"" + children[i] +
+ // "\"");
+ files.push(filename + "/" + children[i]);
+ }
+ }
+ }
+ }
+
+ }
+
+}