[GRASS-SVN] r54850 - in grass-addons/grass7/raster/r.agent: libagent tests

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 2 13:06:11 PST 2013


Author: mic
Date: 2013-02-02 13:06:11 -0800 (Sat, 02 Feb 2013)
New Revision: 54850

Modified:
   grass-addons/grass7/raster/r.agent/libagent/agent.py
   grass-addons/grass7/raster/r.agent/tests/test_agent.py
Log:
basic agent implemented

Modified: grass-addons/grass7/raster/r.agent/libagent/agent.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/agent.py	2013-02-02 20:20:42 UTC (rev 54849)
+++ grass-addons/grass7/raster/r.agent/libagent/agent.py	2013-02-02 21:06:11 UTC (rev 54850)
@@ -30,7 +30,7 @@
 
     def setposition(self, position):
         """
-        Move the agent to a certain position
+        Tell the agent to stand still at a certain position
         @param list coordinate of the current position
         """
         if position and position != []:
@@ -44,14 +44,15 @@
         """
         return self.position
 
-    def move(self, nrofsteps, direction):
-        """
-        Let the agent move
-        @param int the number of steps to walk
-        @param char the direction to go
-        @return list coordinate of the current position
-        """
-        return self.position
+#    def move(self, nrofsteps, direction):
+# not implemented yet
+#        """
+#        Let the agent move
+#        @param int the number of steps to walk
+#        @param char the direction to go
+#        @return list coordinate of the current position
+#        """
+#        return self.position
 
     def age(self):
         """

Modified: grass-addons/grass7/raster/r.agent/tests/test_agent.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_agent.py	2013-02-02 20:20:42 UTC (rev 54849)
+++ grass-addons/grass7/raster/r.agent/tests/test_agent.py	2013-02-02 21:06:11 UTC (rev 54850)
@@ -2,27 +2,40 @@
 import unittest2 as unittest
 #import unittest
 
-from libagent import agent
+from libagent import playground, world, agent
 
 class TestAgent(unittest.TestCase):
     def setUp(self):
-        pass
-#        self.agent = agent.Agent()
+        self.pg = playground.Playground()
+        self.pg.setregion(3,3)
+        self.world = world.World(None, self.pg)
+        self.world.bear(1, [1,1], agent.Agent)
+        self.agent = self.world.agents[0]
 
     def test_setposition(self):
-        pass
+        self.assertTrue(self.agent.getposition() == [1,1])
+        self.agent.setposition([3,3])
+        self.assertTrue(self.agent.getposition() == [3,3])
 
     def test_getposition(self):
-        pass
+        self.assertTrue(self.agent.getposition() == [1,1])
 
-    def test_move(self):
-        pass
+#    def test_move(self):
+# not implemented yet
+#        pass
 
     def test_age(self):
-        pass
+        self.agent.ttl = 1
+        age = self.agent.ttl
+        self.agent.age()
+        self.assertTrue(self.agent.ttl < age)
+        self.agent.age()
+        self.assertTrue(len(self.world.agents) == 0)
 
     def test_snuffit(self):
-        pass
+        self.assertTrue(len(self.world.agents) == 1)
+        self.agent.snuffit()
+        self.assertTrue(len(self.world.agents) == 0)
 
 #    def tearDown(self):
 



More information about the grass-commit mailing list