001    /*
002     * Created on Sep 29, 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.GreedyBestFirstSearch;
017    
018    public class GreedyBestFirstSearchTest extends TestCase {
019            public void testGreedyBestFirstSearch() {
020                    try {
021                            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
022                            // {2,0,5,6,4,8,3,7,1});
023                            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
024                            // {0,8,7,6,5,4,3,2,1});
025                            EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8,
026                                            0, 4, 6, 2, 3, 5 });
027    
028                            Problem problem = new Problem(board,
029                                            new EightPuzzleSuccessorFunction(),
030                                            new EightPuzzleGoalTest(), new ManhattanHeuristicFunction());
031                            Search search = new GreedyBestFirstSearch(new GraphSearch());
032                            SearchAgent agent = new SearchAgent(problem, search);
033                            assertEquals(81, agent.getActions().size());
034                            assertEquals("304", agent.getInstrumentation().getProperty(
035                                            "nodesExpanded"));
036                            assertEquals("268", agent.getInstrumentation().getProperty(
037                                            "queueSize"));
038                            assertEquals("269", agent.getInstrumentation().getProperty(
039                                            "maxQueueSize"));
040    
041                    } catch (Exception e) {
042                            e.printStackTrace();
043                    }
044            }
045    }