001 package aima.test.search.map; 002 003 import junit.framework.TestCase; 004 import aima.basic.Percept; 005 import aima.search.framework.GraphSearch; 006 import aima.search.map.ExtendableMap; 007 import aima.search.map.MapAgent; 008 import aima.search.map.MapEnvironment; 009 import aima.search.uninformed.UniformCostSearch; 010 011 /** 012 * @author Ciaran O'Reilly 013 * 014 */ 015 016 public class MapEnvironmentTest extends TestCase { 017 MapEnvironment me; 018 019 MapAgent ma; 020 021 @Override 022 public void setUp() { 023 ExtendableMap aMap = new ExtendableMap(); 024 aMap.addBidirectionalLink("A", "B", 5.0); 025 aMap.addBidirectionalLink("A", "C", 6.0); 026 aMap.addBidirectionalLink("B", "C", 4.0); 027 aMap.addBidirectionalLink("C", "D", 7.0); 028 aMap.addUnidirectionalLink("B", "E", 14.0); 029 030 me = new MapEnvironment(aMap); 031 ma = new MapAgent(me, new UniformCostSearch(new GraphSearch()), 032 new String[] { "A" }); 033 } 034 035 public void testAddAgent() { 036 me.addAgent(ma, "E"); 037 assertEquals(ma.getAttribute("location"), "E"); 038 } 039 040 public void testExecuteAction() { 041 me.addAgent(ma, "D"); 042 me.executeAction(ma, "C"); 043 assertEquals(ma.getAttribute("location"), "C"); 044 } 045 046 public void testPerceptSeenBy() { 047 me.addAgent(ma, "D"); 048 Percept p = me.getPerceptSeenBy(ma); 049 assertEquals(p.getAttribute("In"), "D"); 050 } 051 }