001    package aima.test.search.searches;
002    
003    import java.util.List;
004    
005    import junit.framework.TestCase;
006    import aima.search.framework.Problem;
007    import aima.search.framework.Search;
008    import aima.search.framework.SearchAgent;
009    import aima.search.nqueens.NQueensBoard;
010    import aima.search.nqueens.NQueensGoalTest;
011    import aima.search.nqueens.NQueensSuccessorFunction;
012    import aima.search.uninformed.IterativeDeepeningSearch;
013    
014    public class IterativeDeepeningSearchTest extends TestCase {
015            public void testIterativeDeepeningSearch() {
016                    try {
017                            Problem problem = new Problem(new NQueensBoard(8),
018                                            new NQueensSuccessorFunction(), new NQueensGoalTest());
019                            Search search = new IterativeDeepeningSearch();
020                            SearchAgent agent = new SearchAgent(problem, search);
021                            List actions = agent.getActions();
022                            assertCorrectPlacement(actions);
023                            assertEquals("3656", agent.getInstrumentation().getProperty(
024                                            "nodesExpanded"));
025    
026                    } catch (Exception e) {
027                            fail("Exception should not occur");
028                    }
029            }
030    
031            private void assertCorrectPlacement(List actions) {
032                    assertEquals(8, actions.size());
033                    assertEquals("placeQueenAt 0  0", actions.get(0));
034                    assertEquals("placeQueenAt 1  4", actions.get(1));
035                    assertEquals("placeQueenAt 2  7", actions.get(2));
036                    assertEquals("placeQueenAt 3  5", actions.get(3));
037                    assertEquals("placeQueenAt 4  2", actions.get(4));
038                    assertEquals("placeQueenAt 5  6", actions.get(5));
039                    assertEquals("placeQueenAt 6  1", actions.get(6));
040                    assertEquals("placeQueenAt 7  3", actions.get(7));
041            }
042    }