001 package aima.test.tvenvironmenttest; 002 003 import junit.framework.TestCase; 004 005 import aima.basic.BasicEnvironmentView; 006 import aima.basic.vaccum.TableDrivenVaccumAgent; 007 import aima.basic.vaccum.TrivialVaccumEnvironment; 008 009 /** 010 * @author Ciaran O'Reilly 011 * 012 */ 013 014 public class TableDrivenVaccumAgentTest extends TestCase { 015 private TableDrivenVaccumAgent agent; 016 017 private StringBuffer envChanges; 018 019 @Override 020 public void setUp() { 021 agent = new TableDrivenVaccumAgent(); 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.stepUntilDone(); 038 039 assertEquals("RightLeftRightNoOP", envChanges.toString()); 040 } 041 042 public void testCleanDirty() { 043 TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Clean", 044 "Dirty"); 045 tve.addAgent(agent, "A"); 046 047 tve.registerView(new BasicEnvironmentView() { 048 @Override 049 public void envChanged(String command) { 050 envChanges.append(command); 051 } 052 }); 053 054 tve.stepUntilDone(); 055 056 assertEquals("RightSuckLeftNoOP", envChanges.toString()); 057 } 058 059 public void testDirtyClean() { 060 TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Dirty", 061 "Clean"); 062 tve.addAgent(agent, "A"); 063 064 tve.registerView(new BasicEnvironmentView() { 065 @Override 066 public void envChanged(String command) { 067 envChanges.append(command); 068 } 069 }); 070 071 tve.stepUntilDone(); 072 073 assertEquals("SuckRightLeftNoOP", envChanges.toString()); 074 } 075 076 public void testDirtyDirty() { 077 TrivialVaccumEnvironment tve = new TrivialVaccumEnvironment("Dirty", 078 "Dirty"); 079 tve.addAgent(agent, "A"); 080 081 tve.registerView(new BasicEnvironmentView() { 082 @Override 083 public void envChanged(String command) { 084 envChanges.append(command); 085 } 086 }); 087 088 tve.stepUntilDone(); 089 090 assertEquals("SuckRightSuckNoOP", envChanges.toString()); 091 } 092 }