001    /*
002     * Created on Sep 21, 2004
003     *
004     */
005    package aima.test.search.csp;
006    
007    import java.util.ArrayList;
008    import java.util.List;
009    
010    import junit.framework.TestCase;
011    import aima.search.csp.Assignment;
012    
013    /**
014     * @author Ravi Mohan
015     * 
016     */
017    public class AssignmentTest extends TestCase {
018            private Assignment assignment;
019    
020            @Override
021            public void setUp() {
022                    List<String> l = new ArrayList<String>();
023                    l.add("x");
024                    l.add("y");
025                    assignment = new Assignment(l);
026            }
027    
028            public void testAssignmentCompletion() {
029                    assertFalse(assignment.isComplete());
030                    assignment.setAssignment("x", "Ravi");
031                    assertFalse(assignment.isComplete());
032                    assignment.setAssignment("y", "AIMA");
033                    assertTrue(assignment.isComplete());
034                    assignment.remove("x");
035                    assertFalse(assignment.isComplete());
036            }
037    
038            public void testAssignmentDefaultVariableSelection() {
039                    assertEquals("x", assignment.selectFirstUnassignedVariable());
040                    assignment.setAssignment("x", "Ravi");
041                    assertEquals("y", assignment.selectFirstUnassignedVariable());
042                    assignment.setAssignment("y", "AIMA");
043                    assertEquals(null, assignment.selectFirstUnassignedVariable());
044            }
045    
046    }