public void TestSearchClassCreation() { int size = 9; Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int> problem = NPuzzleUtils.CreateProblem(size); Heuristics.HeuristicFunction <NPuzzleState <int[]>, int, int> handler = Heuristics.NPuzzleHeuristics.ManhattanDistance; //Search.BestFirstGraphSearch<int[], int, int, int> bfgs = new Search.BestFirstGraphSearch<int[], int, int, int>(problem, handler); }
public void TestExpand() { int[] goal = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; NPuzzleState <int[]> goalState = new NPuzzleState <int[]>(goal); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> rootNode = new SearchTreeNode.Node <NPuzzleState <int[]>, int, int>(goalState); List <SearchTreeNode.Node <NPuzzleState <int[]>, int, int> > expandedNodes; Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int> problem = NPuzzleUtils.CreateProblem(9); expandedNodes = rootNode.Expand(problem); List <SearchTreeNode.Node <NPuzzleState <int[]>, int, int> > testNodes = new List <SearchTreeNode.Node <NPuzzleState <int[]>, int, int> >(); //! actions for goal are -1 and 2 //! state resulting from action 2 int[] s1 = { 1, 2, 3, 4, 5, 9, 7, 8, 6 }; NPuzzleState <int[]> s1State = new NPuzzleState <int[]>(s1); //! state resulting from -1 int[] s2 = { 1, 2, 3, 4, 5, 6, 7, 9, 8 }; NPuzzleState <int[]> s2State = new NPuzzleState <int[]>(s2); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> node2 = new SearchTreeNode.Node <NPuzzleState <int[]>, int, int>(s1State, rootNode, 2, 1); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> node3 = new SearchTreeNode.Node <NPuzzleState <int[]>, int, int>(s2State, rootNode, -1, 1); testNodes.Add(node3); testNodes.Add(node2); Assert.AreEqual(testNodes.Count, expandedNodes.Count); Assert.AreEqual(expandedNodes[0].state, node3.state); // Assert.True(expandedNodes[0].state.Equals( node3.state)); Assert.AreEqual(expandedNodes[0].parent, node3.parent); Assert.True(expandedNodes[0].parent.Equals(node3.parent)); Assert.AreEqual(expandedNodes[0].action, node3.action); Assert.True(expandedNodes[0].action.Equals(node3.action)); Assert.AreEqual(expandedNodes[0].depth, node3.depth); Assert.True(expandedNodes[0].depth.Equals(node3.depth)); Assert.AreEqual(expandedNodes[0].pathCost, node3.pathCost); Assert.True(expandedNodes[0].pathCost.Equals(node3.pathCost)); // Assert.True(expandedNodes[0].Equals(node3)); // Assert.AreEqual(expandedNodes[0], node3); // Assert.AreEqual(expandedNodes[1], node2); // CollectionAssert.AreEqual(testNodes, expandedNodes); // Assert.That(testNodes, Is.EquivalentTo(expandedNodes)); }
public void TestChildNode() { int[] goal = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; NPuzzleState <int[]> goalState = new NPuzzleState <int[]>(goal); //! action -1 int[] s1 = { 1, 2, 3, 4, 5, 9, 7, 8, 6 }; NPuzzleState <int[]> s1State = new NPuzzleState <int[]>(s1); int[] s2 = { 1, 2, 3, 4, 5, 6, 7, 9, 8 }; NPuzzleState <int[]> s2State = new NPuzzleState <int[]>(s2); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> node = new SearchTreeNode.Node <NPuzzleState <int[]>, int, int>(goalState); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> childNode = new SearchTreeNode.Node <NPuzzleState <int[]>, int, int>(s2State, node, -1, 1); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> childNode2 = new SearchTreeNode.Node <NPuzzleState <int[]>, int, int>(s1State, node, 2, 1); Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int> problem = NPuzzleUtils.CreateProblem(9); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> expectedNode = node.ChildNode(problem, -1); SearchTreeNode.Node <NPuzzleState <int[]>, int, int> expectedNode2 = node.ChildNode(problem, 2); //! Tests Assert.AreEqual(node.depth, 0); Assert.AreEqual(expectedNode.parent, childNode.parent); Assert.AreEqual(expectedNode.pathCost, childNode.pathCost); Assert.AreEqual(expectedNode.state, childNode.state); Assert.AreEqual(expectedNode.action, -1); Assert.AreEqual(expectedNode.depth, 1); Assert.AreEqual(expectedNode2.parent, childNode2.parent); Assert.AreEqual(expectedNode2.pathCost, childNode2.pathCost); Assert.AreEqual(expectedNode2.state, childNode2.state); Assert.AreEqual(expectedNode2.action, 2); Assert.AreEqual(expectedNode2.depth, 1); }