001    package aima.test.search.nqueens;
002    
003    import junit.framework.TestCase;
004    import aima.basic.XYLocation;
005    import aima.search.nqueens.NQueensBoard;
006    import aima.search.nqueens.NQueensGoalTest;
007    
008    /**
009     * @author Ravi Mohan
010     * 
011     */
012    public class NQueensGoalTestTest extends TestCase {
013            NQueensGoalTest goalTest;
014    
015            NQueensBoard board;
016    
017            @Override
018            public void setUp() {
019                    goalTest = new NQueensGoalTest();
020                    board = new NQueensBoard(8);
021            }
022    
023            public void testEmptyBoard() {
024                    assertFalse(goalTest.isGoalState(board));
025            }
026    
027            public void testSingleSquareBoard() {
028                    board = new NQueensBoard(1);
029                    assertFalse(goalTest.isGoalState(board));
030                    board.addQueenAt(new XYLocation(0, 0));
031                    assertTrue(goalTest.isGoalState(board));
032            }
033    
034            public void testInCorrectPlacement() {
035                    assertFalse(goalTest.isGoalState(board));
036                    // This is the configuration of Figure 3.5 (b) in AIMA 2nd Edition
037                    board.addQueenAt(new XYLocation(0, 0));
038                    board.addQueenAt(new XYLocation(1, 2));
039                    board.addQueenAt(new XYLocation(2, 4));
040                    board.addQueenAt(new XYLocation(3, 6));
041                    board.addQueenAt(new XYLocation(4, 1));
042                    board.addQueenAt(new XYLocation(5, 3));
043                    board.addQueenAt(new XYLocation(6, 5));
044                    board.addQueenAt(new XYLocation(7, 7));
045                    assertFalse(goalTest.isGoalState(board));
046            }
047    
048            public void testCorrectPlacement() {
049    
050                    assertFalse(goalTest.isGoalState(board));
051                    // This is the configuration of Figure 5.9 (c) in AIMA 2nd Edition
052                    board.addQueenAt(new XYLocation(0, 1));
053                    board.addQueenAt(new XYLocation(1, 4));
054                    board.addQueenAt(new XYLocation(2, 6));
055                    board.addQueenAt(new XYLocation(3, 3));
056                    board.addQueenAt(new XYLocation(4, 0));
057                    board.addQueenAt(new XYLocation(5, 7));
058                    board.addQueenAt(new XYLocation(6, 5));
059                    board.addQueenAt(new XYLocation(7, 2));
060    
061                    assertTrue(goalTest.isGoalState(board));
062            }
063    }