From 45b92fdf3bee2ebb57383569fdd00d6ab9f4392c Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sun, 18 Dec 2011 07:38:06 +0000 Subject: [PATCH] DroidFishTest: Added tests for GameTree.goNode(). --- .../droidfish/gamelogic/GameTreeTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/DroidFishTest/src/org/petero/droidfish/gamelogic/GameTreeTest.java b/DroidFishTest/src/org/petero/droidfish/gamelogic/GameTreeTest.java index af03487..4255166 100644 --- a/DroidFishTest/src/org/petero/droidfish/gamelogic/GameTreeTest.java +++ b/DroidFishTest/src/org/petero/droidfish/gamelogic/GameTreeTest.java @@ -652,4 +652,44 @@ public class GameTreeTest extends TestCase { assertTrue(pgn.indexOf("cxb8=N") >= 0); // ... but PGN promotions do have the = sign assertTrue(pgn.indexOf("cxd8=R+") >= 0); } + + public final void testGoNode() throws ChessParseError { + GameTree gt = new GameTree(null); + PGNOptions options = new PGNOptions(); + options.imp.variations = true; + options.imp.comments = false; + options.imp.nag = false; + boolean res = gt.readPGN("e4 (d4 d5 c4) e5 Nf3 Nc6 Bb5 (Bc4 Bc5 (Nf6)) a6", options); + assertEquals(true, res); + assertEquals("*e4 e5 Nf3 Nc6 Bb5 a6", getMoveListAsString(gt)); + gt.goForward(-1); + Node ne4 = gt.currentNode; + for (int i = 0; i < 5; i++) gt.goForward(-1); + assertEquals("e4 e5 Nf3 Nc6 Bb5 a6*", getMoveListAsString(gt)); + Node na6 = gt.currentNode; + gt.goNode(gt.rootNode); + assertEquals("*e4 e5 Nf3 Nc6 Bb5 a6", getMoveListAsString(gt)); + gt.goNode(na6); + assertEquals("e4 e5 Nf3 Nc6 Bb5 a6*", getMoveListAsString(gt)); + gt.goBack(); + gt.goBack(); + gt.goForward(1); + gt.goForward(-1); + Node nBc5 = gt.currentNode; + assertEquals("e4 e5 Nf3 Nc6 Bc4 Bc5*", getMoveListAsString(gt)); + gt.goNode(na6); + assertEquals("e4 e5 Nf3 Nc6 Bb5 a6*", getMoveListAsString(gt)); + gt.goNode(nBc5); + gt.goBack(); + gt.goForward(1); + assertEquals("e4 e5 Nf3 Nc6 Bc4 Nf6*", getMoveListAsString(gt)); + gt.goNode(gt.rootNode); + gt.goForward(1); + assertEquals("d4* d5 c4", getMoveListAsString(gt)); + gt.goNode(ne4); + assertEquals("e4* e5 Nf3 Nc6 Bc4 Nf6", getMoveListAsString(gt)); + gt.goNode(na6); + gt.goNode(ne4); + assertEquals("e4* e5 Nf3 Nc6 Bb5 a6", getMoveListAsString(gt)); + } }