001 package aima.test.search.nqueens; 002 003 import java.util.List; 004 005 import junit.framework.TestCase; 006 import aima.search.framework.Successor; 007 import aima.search.nqueens.NQueensBoard; 008 import aima.search.nqueens.NQueensSuccessorFunction; 009 010 /** 011 * @author Ravi Mohan 012 * 013 */ 014 015 public class NQueensSuccessorFunctionTest extends TestCase { 016 NQueensSuccessorFunction successorFunction; 017 018 NQueensBoard oneBoard; 019 020 NQueensBoard eightBoard; 021 022 @Override 023 public void setUp() { 024 successorFunction = new NQueensSuccessorFunction(); 025 oneBoard = new NQueensBoard(1); 026 eightBoard = new NQueensBoard(8); 027 } 028 029 public void testSimpleBoardSuccessorGenerator() { 030 List successors = successorFunction.getSuccessors(oneBoard); 031 assertEquals(1, successors.size()); 032 Successor successor = (Successor) successors.get(0); 033 NQueensBoard next = (NQueensBoard) successor.getState(); 034 assertEquals(1, next.getNumberOfQueensOnBoard()); 035 } 036 037 public void testComplexBoardSuccessorGenerator() { 038 List successors = successorFunction.getSuccessors(eightBoard); 039 assertEquals(8, successors.size()); 040 Successor successor = (Successor) successors.get(0); 041 NQueensBoard next = (NQueensBoard) successor.getState(); 042 assertEquals(1, next.getNumberOfQueensOnBoard()); 043 044 successors = successorFunction.getSuccessors(next); 045 assertEquals(6, successors.size()); 046 } 047 048 }