001    /*
002     * Created on Sep 28, 2005
003     *
004     */
005    package aima.test.search.searches;
006    
007    import junit.framework.TestCase;
008    import aima.search.eightpuzzle.EightPuzzleBoard;
009    import aima.search.eightpuzzle.EightPuzzleGoalTest;
010    import aima.search.eightpuzzle.EightPuzzleSuccessorFunction;
011    import aima.search.eightpuzzle.ManhattanHeuristicFunction;
012    import aima.search.framework.GraphSearch;
013    import aima.search.framework.Problem;
014    import aima.search.framework.Search;
015    import aima.search.framework.SearchAgent;
016    import aima.search.informed.AStarSearch;
017    
018    public class AStarSearchTest extends TestCase {
019            public void testAStarSearch() {
020                    // added to narrow down bug report filed by L.N.Sudarshan of
021                    // Thoughtworks and Xin Lu of UCI
022                    try {
023                            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
024                            // {2,0,5,6,4,8,3,7,1});
025                            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
026                            // {0,8,7,6,5,4,3,2,1});
027                            EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8,
028                                            0, 4, 6, 2, 3, 5 });
029    
030                            Problem problem = new Problem(board,
031                                            new EightPuzzleSuccessorFunction(),
032                                            new EightPuzzleGoalTest(), new ManhattanHeuristicFunction());
033                            Search search = new AStarSearch(new GraphSearch());
034                            SearchAgent agent = new SearchAgent(problem, search);
035                            assertEquals(23, agent.getActions().size());
036                            assertEquals("906", agent.getInstrumentation().getProperty(
037                                            "nodesExpanded"));
038                            assertEquals("914", agent.getInstrumentation().getProperty(
039                                            "queueSize"));
040                            assertEquals("920", agent.getInstrumentation().getProperty(
041                                            "maxQueueSize"));
042    
043                    } catch (Exception e) {
044                            e.printStackTrace();
045                    }
046            }
047    
048    }