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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 16 10:21:22 PST 2013


Author: mic
Date: 2013-01-16 10:21:21 -0800 (Wed, 16 Jan 2013)
New Revision: 54676

Modified:
   grass-addons/grass7/raster/r.agent/libagent/playground.py
   grass-addons/grass7/raster/r.agent/tests/test_grassland.py
   grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
implement tests and createlayer

Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-01-16 16:25:14 UTC (rev 54675)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-01-16 18:21:21 UTC (rev 54676)
@@ -9,7 +9,7 @@
               for details.
 """
 
-import error
+import numpy, error
 
 class Playground(object):
     """A Playground is a major component of a World, defining
@@ -18,7 +18,7 @@
     def __init__(self):
         self.layers = dict()
 #TODO
-        self.region = dict(n=0,s=0,w=0,e=0,rows=0,cols=0)
+        self.region = dict(n=1,s=0,w=0,e=1,rows=1,cols=1)
 
     def getregion(self):
         """
@@ -55,11 +55,14 @@
         @param string file name if it is to be created from an existing file
         @param boolean whether to overwrite an existing layer
         """
-        #TODO rows vs. cols
-        #TODO import from file
-        layer = []
-        for i in range(self.region["rows"]):
-            l.append( [[] for j in range(self.region["cols"])])
+        r = self.region["rows"]
+        c = self.region["cols"]
+        layer = numpy.zeros(r*c).reshape((r,c))
+
+        if filename:
+            #TODO import from file
+            pass
+
         self.setlayer(layername, layer)
 
     def getlayer(self, layername):

Modified: grass-addons/grass7/raster/r.agent/tests/test_grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_grassland.py	2013-01-16 16:25:14 UTC (rev 54675)
+++ grass-addons/grass7/raster/r.agent/tests/test_grassland.py	2013-01-16 18:21:21 UTC (rev 54676)
@@ -16,6 +16,8 @@
         self.assertIsNotNone(self.pg.getbound("s"))
         self.assertIsNotNone(self.pg.getbound("w"))
         self.assertIsNotNone(self.pg.getbound("e"))
+        self.assertTrue(self.pg.getbound("n")>self.pg.getbound("s"))
+        self.assertTrue(self.pg.getbound("e")>self.pg.getbound("w"))
 
     #def test_setlayer(self):
        # gets tested in createlayer and super()/Playground
@@ -28,6 +30,8 @@
         self.pg.createlayer("foo", "foo")
         self.assertTrue(self.pg.layers.has_key("foo"))
         self.assertTrue(self.pg.grassmapnames.has_key("foo"))
+        self.assertEqual(len(self.pg.layers["foo"]), self.pg.region["rows"])
+        self.assertEqual(len(self.pg.layers["foo"][0]), self.pg.region["cols"])
 
     def test_getlayer(self):
         self.pg.layers["foo"] = [0]

Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-01-16 16:25:14 UTC (rev 54675)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-01-16 18:21:21 UTC (rev 54676)
@@ -16,6 +16,8 @@
         self.assertIsNotNone(self.pg.getbound("s"))
         self.assertIsNotNone(self.pg.getbound("w"))
         self.assertIsNotNone(self.pg.getbound("e"))
+        self.assertTrue(self.pg.getbound("n")>self.pg.getbound("s"))
+        self.assertTrue(self.pg.getbound("e")>self.pg.getbound("w"))
 
     def test_setlayer(self):
         layer = [0]
@@ -32,7 +34,8 @@
         #TODO from file, better test manually?
         self.pg.createlayer("foo")
         self.assertTrue(self.pg.layers.has_key("foo"))
-        #TODO rows / cols
+        self.assertEqual(len(self.pg.layers["foo"]), self.pg.region["rows"])
+        self.assertEqual(len(self.pg.layers["foo"][0]), self.pg.region["cols"])
 
     def test_getlayer(self):
         self.pg.layers["foo"] = [0]



More information about the grass-commit mailing list