001    package aima.test.tvenvironmenttest;
002    
003    import junit.framework.TestCase;
004    
005    import aima.basic.BasicEnvironmentView;
006    import aima.basic.vaccum.SimpleReflexVaccumAgent;
007    import aima.basic.vaccum.TrivialVaccumEnvironment;
008    
009    /**
010     * @author Ciaran O'Reilly
011     * 
012     */
013    
014    public class SimpleReflexVaccumAgentTest extends TestCase {
015            private SimpleReflexVaccumAgent agent;
016    
017            private StringBuffer envChanges;
018    
019            @Override
020            public void setUp() {
021                    agent = new SimpleReflexVaccumAgent();
022                    envChanges = new StringBuffer();
023            }
024    
025            public void testCleanClean() {
026                    TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Clean",
027                                    "Clean");
028                    tve.addAgent(agent, "A");
029    
030                    tve.registerView(new BasicEnvironmentView() {
031                            @Override
032                            public void envChanged(String command) {
033                                    envChanges.append(command);
034                            }
035                    });
036    
037                    tve.step(8);
038    
039                    assertEquals("RightLeftRightLeftRightLeftRightLeft", envChanges
040                                    .toString());
041            }
042    
043            public void testCleanDirty() {
044                    TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Clean",
045                                    "Dirty");
046                    tve.addAgent(agent, "A");
047    
048                    tve.registerView(new BasicEnvironmentView() {
049                            @Override
050                            public void envChanged(String command) {
051                                    envChanges.append(command);
052                            }
053                    });
054    
055                    tve.step(8);
056    
057                    assertEquals("RightSuckLeftRightLeftRightLeftRight", envChanges
058                                    .toString());
059            }
060    
061            public void testDirtyClean() {
062                    TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Dirty",
063                                    "Clean");
064                    tve.addAgent(agent, "A");
065    
066                    tve.registerView(new BasicEnvironmentView() {
067                            @Override
068                            public void envChanged(String command) {
069                                    envChanges.append(command);
070                            }
071                    });
072    
073                    tve.step(8);
074    
075                    assertEquals("SuckRightLeftRightLeftRightLeftRight", envChanges
076                                    .toString());
077            }
078    
079            public void testDirtyDirty() {
080                    TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Dirty",
081                                    "Dirty");
082                    tve.addAgent(agent, "A");
083    
084                    tve.registerView(new BasicEnvironmentView() {
085                            @Override
086                            public void envChanged(String command) {
087                                    envChanges.append(command);
088                            }
089                    });
090    
091                    tve.step(8);
092    
093                    assertEquals("SuckRightSuckLeftRightLeftRightLeft", envChanges
094                                    .toString());
095            }
096    }