[jgogears commit] r60 - trunk/jgogears/jgogears/engine

0 views
Skip to first unread message

codesite...@google.com

unread,
Mar 10, 2008, 3:17:29 PM3/10/08
to jgog...@googlegroups.com
Author: syeates
Date: Mon Mar 10 12:11:46 2008
New Revision: 60

Added:
trunk/jgogears/jgogears/engine/TrainerTest.java

Log:
add trainer tests

Added: trunk/jgogears/jgogears/engine/TrainerTest.java
==============================================================================
--- (empty file)
+++ trunk/jgogears/jgogears/engine/TrainerTest.java Mon Mar 10 12:11:46 2008
@@ -0,0 +1,119 @@
+/**
+ *
+ */
+package jgogears.engine;
+
+import junit.framework.TestCase;
+import java.util.*;
+import java.io.*;
+
+/**
+ * Test the trainer
+ *
+ * @author syeates
+ */
+public class TrainerTest extends TestCase {
+
+ public void testLoadAllSGFfiles() throws IOException {
+ Collection<String> plain = Trainer.loadAllSGFfiles();
+ assertNotNull(plain);
+ Iterator<String> iterator = plain.iterator();
+ assertNotNull(iterator);
+ int count = 0;
+ TreeSet<String> tree = new TreeSet();
+
+ while (iterator.hasNext()) {
+ String s = iterator.next();
+ assertNotNull(s);
+ count++;
+ assertFalse(tree.contains(s));
+ tree.add(s);
+ }
+ }
+
+ public void testLoadAllSGFfilesGeneric() throws IOException {
+ Collection plain = Trainer.loadAllSGFfiles();
+ assertNotNull(plain);
+ Iterator iterator = plain.iterator();
+ assertNotNull(iterator);
+ int count = 0;
+ TreeSet tree = new TreeSet();
+
+ while (iterator.hasNext()) {
+ String s = (String) iterator.next();
+ assertNotNull(s);
+ count++;
+ assertFalse(tree.contains(s));
+ tree.add(s);
+ }
+ }
+
+ public void testLoadAllSGFfilesString() throws IOException {
+ Collection<String> plain = Trainer.loadAllSGFfiles(Trainer.LIBRARY);
+ assertNotNull(plain);
+ Iterator<String> iterator = plain.iterator();
+ assertNotNull(iterator);
+ int count = 0;
+ TreeSet<String> tree = new TreeSet();
+
+ while (iterator.hasNext()) {
+ String s = iterator.next();
+ assertNotNull(s);
+ count++;
+ assertFalse(tree.contains(s));
+ tree.add(s);
+ }
+
+ }
+
+ public void testTrainSingle() throws IOException {
+ try {
+ Trainer trainer = new Trainer();
+ assertNotNull(trainer);
+ Model model = new Model();
+ assertNotNull(model);
+ trainer.train(1, model);
+ assertNotNull(trainer);
+ assertTrue(model.getGamesTrained() == 1);
+ assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 1);
+ } catch (IOException e) {
+ fail("" + e);
+ }
+ }
+
+ public void testTrainTwo() throws IOException {
+ try {
+ Trainer trainer = new Trainer();
+ assertNotNull(trainer);
+ Model model = new Model();
+ assertNotNull(model);
+ trainer.train(2, model);
+ assertNotNull(trainer);
+ assertTrue(model.getGamesTrained() == 2);
+ assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 1);
+ } catch (IOException e) {
+ fail("" + e);
+ }
+ }
+
+ public void testTrainDouble() throws IOException {
+ try {
+ Trainer trainer = new Trainer();
+ assertNotNull(trainer);
+ Model model = new Model();
+ assertNotNull(model);
+ trainer.train(2, model);
+ assertNotNull(model);
+ assertTrue(model.getGamesTrained() == 2);
+ assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 20);
+ trainer.train(2, model);
+ assertNotNull(trainer);
+ assertNotNull(model);
+ assertTrue(model.getGamesTrained() == 4);
+ assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 100);
+ } catch (IOException e) {
+ fail("" + e);
+ }
+ }
+
+}

Reply all
Reply to author
Forward
0 new messages