001 /* 002 * Created by IntelliJ IDEA. 003 * User: rrmohan 004 * Date: Jan 20, 2003 005 * Time: 9:57:10 AM 006 * To change template for new class use 007 * Code Style | Class Templates options (Tools | IDE Options). 008 */ 009 package aima.test.tvenvironmenttest; 010 011 import junit.framework.TestCase; 012 import aima.basic.vaccum.ModelBasedTVEVaccumAgent; 013 import aima.basic.vaccum.TrivialVaccumEnvironment; 014 015 /** 016 * @author Ravi Mohan 017 * 018 */ 019 020 public class ModelBasedTVEVaccumAgentTest extends TestCase { 021 TrivialVaccumEnvironment tve, tve2, tve3, tve4; 022 023 ModelBasedTVEVaccumAgent a; 024 025 public ModelBasedTVEVaccumAgentTest(String name) { 026 super(name); 027 } 028 029 @Override 030 public void setUp() { 031 tve = new TrivialVaccumEnvironment("Dirty", "Dirty"); 032 tve2 = new TrivialVaccumEnvironment("Clean", "Clean"); 033 tve3 = new TrivialVaccumEnvironment("Clean", "Dirty"); 034 tve4 = new TrivialVaccumEnvironment("Dirty", "Clean"); 035 a = new ModelBasedTVEVaccumAgent(); 036 } 037 038 public void testAgentActionNumber1() { 039 tve.addAgent(a, "A"); 040 assertEquals("A", tve.getAgentLocation(a)); 041 assertEquals(1, tve.getAgents().size()); 042 tve.step(); // cleans location A 043 assertEquals("A", tve.getAgentLocation(a)); 044 assertEquals("Clean", tve.getLocation1Status()); 045 tve.step(); // moves to lcation B 046 assertEquals("B", tve.getAgentLocation(a)); 047 assertEquals("Dirty", tve.getLocation2Status()); 048 tve.step(); // cleans location B 049 assertEquals("B", tve.getAgentLocation(a)); 050 assertEquals("Clean", tve.getLocation2Status()); 051 tve.step(); // NOOP 052 assertEquals("B", tve.getAgentLocation(a)); 053 assertEquals(19, tve.getAgentperformance(a)); 054 055 } 056 057 public void testAgentActionNumber2() { 058 tve.addAgent(a, "B"); 059 assertEquals("B", tve.getAgentLocation(a)); 060 assertEquals(1, tve.getAgents().size()); 061 tve.step(); // cleans location B 062 assertEquals("B", tve.getAgentLocation(a)); 063 assertEquals("Clean", tve.getLocation2Status()); 064 tve.step(); // moves to lcation A 065 assertEquals("A", tve.getAgentLocation(a)); 066 assertEquals("Dirty", tve.getLocation1Status()); 067 tve.step(); // cleans location A 068 assertEquals("A", tve.getAgentLocation(a)); 069 assertEquals("Clean", tve.getLocation1Status()); 070 tve.step(); // NOOP 071 assertEquals("A", tve.getAgentLocation(a)); 072 assertEquals("Clean", tve.getLocation1Status()); 073 assertEquals("Clean", tve.getLocation2Status()); 074 assertEquals(19, tve.getAgentperformance(a)); 075 076 } 077 078 public void testAgentActionNumber3() { 079 tve2.addAgent(a, "A"); 080 assertEquals("A", tve2.getAgentLocation(a)); 081 assertEquals(1, tve2.getAgents().size()); 082 tve2.step(); // moves to location B 083 assertEquals("B", tve2.getAgentLocation(a)); 084 assertEquals("Clean", tve2.getLocation2Status()); 085 tve2.step(); // NOOP 086 assertEquals("B", tve2.getAgentLocation(a)); 087 assertEquals("Clean", tve2.getLocation1Status()); 088 assertEquals("Clean", tve2.getLocation2Status()); 089 assertEquals(-1, tve.getAgentperformance(a)); 090 091 } 092 093 public void testAgentActionNumber4() { 094 tve2.addAgent(a, "B"); 095 assertEquals("B", tve2.getAgentLocation(a)); 096 assertEquals(1, tve2.getAgents().size()); 097 tve2.step(); // moves to location A 098 assertEquals("A", tve2.getAgentLocation(a)); 099 assertEquals("Clean", tve2.getLocation1Status()); 100 tve2.step(); // NOOP 101 assertEquals("A", tve2.getAgentLocation(a)); 102 assertEquals("Clean", tve2.getLocation1Status()); 103 assertEquals("Clean", tve2.getLocation2Status()); 104 assertEquals(-1, tve.getAgentperformance(a)); 105 } 106 107 public void testAgentActionNumber5() { 108 tve3.addAgent(a, "A"); 109 assertEquals("A", tve3.getAgentLocation(a)); 110 assertEquals(1, tve3.getAgents().size()); 111 tve3.step(); // moves to B 112 assertEquals("B", tve3.getAgentLocation(a)); 113 assertEquals("Dirty", tve3.getLocation2Status()); 114 tve3.step(); // cleans location B 115 assertEquals("B", tve3.getAgentLocation(a)); 116 assertEquals("Clean", tve3.getLocation2Status()); 117 tve3.step(); // NOOP 118 assertEquals("B", tve3.getAgentLocation(a)); 119 assertEquals("Clean", tve3.getLocation1Status()); 120 assertEquals("Clean", tve3.getLocation2Status()); 121 assertEquals(9, tve.getAgentperformance(a)); 122 123 } 124 125 public void testAgentActionNumber6() { 126 tve3.addAgent(a, "B"); 127 assertEquals("B", tve3.getAgentLocation(a)); 128 assertEquals(1, tve3.getAgents().size()); 129 tve3.step(); // cleans B 130 assertEquals("B", tve3.getAgentLocation(a)); 131 assertEquals("Clean", tve3.getLocation2Status()); 132 tve3.step(); // moves to A 133 assertEquals("A", tve3.getAgentLocation(a)); 134 assertEquals("Clean", tve3.getLocation1Status()); 135 tve3.step(); // NOOP 136 assertEquals("A", tve3.getAgentLocation(a)); 137 assertEquals("Clean", tve3.getLocation1Status()); 138 assertEquals("Clean", tve3.getLocation2Status()); 139 assertEquals(9, tve.getAgentperformance(a)); 140 141 } 142 143 public void testAgentActionNumber7() { 144 tve4.addAgent(a, "A"); 145 assertEquals("A", tve4.getAgentLocation(a)); 146 assertEquals(1, tve4.getAgents().size()); 147 tve4.step(); // cleans A 148 assertEquals("A", tve4.getAgentLocation(a)); 149 assertEquals("Clean", tve4.getLocation1Status()); 150 tve4.step(); // moves to B 151 assertEquals("B", tve4.getAgentLocation(a)); 152 assertEquals("Clean", tve4.getLocation2Status()); 153 tve4.step(); // NOOP 154 assertEquals("B", tve4.getAgentLocation(a)); 155 assertEquals("Clean", tve4.getLocation1Status()); 156 assertEquals("Clean", tve4.getLocation2Status()); 157 assertEquals(9, tve.getAgentperformance(a)); 158 159 } 160 161 public void testAgentActionNumber8() { 162 tve4.addAgent(a, "B"); 163 assertEquals("B", tve4.getAgentLocation(a)); 164 assertEquals(1, tve4.getAgents().size()); 165 tve4.step(); // moves to A 166 assertEquals("A", tve4.getAgentLocation(a)); 167 assertEquals("Dirty", tve4.getLocation1Status()); 168 tve4.step(); // cleans A 169 assertEquals("A", tve4.getAgentLocation(a)); 170 assertEquals("Clean", tve4.getLocation1Status()); 171 tve4.step(); // NOOP 172 assertEquals("A", tve4.getAgentLocation(a)); 173 assertEquals("Clean", tve4.getLocation1Status()); 174 assertEquals("Clean", tve4.getLocation2Status()); 175 assertEquals(9, tve.getAgentperformance(a)); 176 177 } 178 179 }