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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 18 07:00:30 PDT 2013


Author: mic
Date: 2013-05-18 07:00:30 -0700 (Sat, 18 May 2013)
New Revision: 56299

Modified:
   grass-addons/grass7/raster/r.agent/libagent/anthill.py
   grass-addons/grass7/raster/r.agent/tests/test_anthill.py
Log:
add shortcut methods

Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-05-18 13:30:20 UTC (rev 56298)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-05-18 14:00:30 UTC (rev 56299)
@@ -109,3 +109,21 @@
             # count down
             rounds -= 1
 
+    def getpheromone(self, position):
+        """
+        Return the pheromone value at a certain position
+        @param position the position in question
+        @return the value of interest
+        """
+        return self.playground.getcellvalue(Anthill.RESULT, position)
+
+    def setpheromone(self, position, intensity=None):
+        """
+        Mark a certain position with pheromone
+        @param position the position in question
+        @param intensity the value to be set
+        """
+        if not intensity:
+            intensity = self.stepintensity
+        self.playground.setcellvalue(Anthill.RESULT, position, intensity)
+

Modified: grass-addons/grass7/raster/r.agent/tests/test_anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_anthill.py	2013-05-18 13:30:20 UTC (rev 56298)
+++ grass-addons/grass7/raster/r.agent/tests/test_anthill.py	2013-05-18 14:00:30 UTC (rev 56299)
@@ -49,6 +49,22 @@
         # TODO: as sort of the mainloop, just let it run a few times?
         pass
 
+    def test_getpheromone(self):
+        self.assertNotEqual(9,
+            self.world.playground.layers[anthill.Anthill.RESULT][0][0])
+        self.world.playground.layers[anthill.Anthill.RESULT][0][0] = 9
+        self.assertEqual(9, self.world.getpheromone([0,0]))
+
+    def test_setpheromone(self):
+        self.world.setpheromone([0,0], 5)
+        self.assertNotEqual(4,
+            self.world.playground.layers[anthill.Anthill.RESULT][0][0])
+        self.world.setpheromone([0,0], 4)
+        self.assertNotEqual(5,
+            self.world.playground.layers[anthill.Anthill.RESULT][0][0])
+        self.assertEqual(4,
+            self.world.playground.layers[anthill.Anthill.RESULT][0][0])
+
     def volatilize(self):
         # gets tested in Playground, except for setting the values..
         pass



More information about the grass-commit mailing list