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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 18 06:30:20 PDT 2013


Author: mic
Date: 2013-05-18 06:30:20 -0700 (Sat, 18 May 2013)
New Revision: 56298

Modified:
   grass-addons/grass7/raster/r.agent/libagent/playground.py
   grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
add shortcut method

Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-05-18 12:55:35 UTC (rev 56297)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-05-18 13:30:20 UTC (rev 56298)
@@ -194,6 +194,23 @@
                                                     position[1]+1]))
         return positions
 
+    def getcellvalue(self, layername, position):
+        """
+        Get the content of a certain cell in a layer specified.
+        @param layername the name of the layer to query
+        @param position the exact position of the cell in question
+        @return long the value stored in the cell
+        """
+        return self.layers[layername][position[0]][position[1]]
+
+    def setcellvalue(self, layername, position, value):
+        """
+        Set the content of a certain cell in a layer specified.
+        @param layername the name of the layer to be edited
+        @param position the exact position of the cell in question
+        """
+        self.layers[layername][position[0]][position[1]] = value
+
     def decaycellvalues(self, layername, halflife, minimum=0):
         """
         Let the values in each cell decay, volatilize or evaporate over time.

Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-05-18 12:55:35 UTC (rev 56297)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-05-18 13:30:20 UTC (rev 56298)
@@ -116,6 +116,22 @@
         self.assertTrue(ps[2])
         self.assertFalse(ps[3])
 
+    def test_getcellvalue(self):
+        l = "bar"
+        self.pg.createlayer(l)
+        self.pg.layers[l][0][0] = 0
+        self.assertNotEqual(101, self.pg.getcellvalue(l, [0,0]))
+        self.pg.layers[l][0][0] = 101
+        self.assertEqual(101, self.pg.getcellvalue(l, [0,0]))
+
+    def test_setcellvalue(self):
+        l = "bar"
+        self.pg.createlayer(l)
+        self.pg.layers[l][0][0] = 0
+        self.assertNotEqual(101, self.pg.layers[l][0][0])
+        self.pg.setcellvalue(l, [0,0], 101)
+        self.assertEqual(101, self.pg.getcellvalue(l, [0,0]))
+
     def test_decaycellvalues(self):
         l = "bar"
         self.pg.createlayer(l)



More information about the grass-commit mailing list