[GRASS-SVN] r74229 - in grass/trunk/raster/r.random: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 13 00:12:18 PDT 2019


Author: lucadelu
Date: 2019-03-13 00:12:18 -0700 (Wed, 13 Mar 2019)
New Revision: 74229

Added:
   grass/trunk/raster/r.random/testsuite/
   grass/trunk/raster/r.random/testsuite/test_r.random.py
   grass/trunk/raster/r.random/testsuite/testrandom.py
Log:
r.random: added tests from GCI 2018

Added: grass/trunk/raster/r.random/testsuite/test_r.random.py
===================================================================
--- grass/trunk/raster/r.random/testsuite/test_r.random.py	                        (rev 0)
+++ grass/trunk/raster/r.random/testsuite/test_r.random.py	2019-03-13 07:12:18 UTC (rev 74229)
@@ -0,0 +1,117 @@
+"""
+Name:        r.random test
+Purpose:    Tests r.random module and some of its options.
+
+Author:     Shubham Sharma, Google Code-in 2018
+Copyright:  (C) 2018 by Shubham Sharma and the GRASS Development Team
+Licence:    This program is free software under the GNU General Public
+            License (>=v2). Read the file COPYING that comes with GRASS
+            for details.
+"""
+
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+
+
+class TestRasterTile(TestCase):
+    input = 'landcover_1m'
+    npoints = '20'
+    raster = 'landcover_1m_raster_random'
+    vector = "landcover_1m_vector_random"
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+        cls.runModule('g.region', raster=cls.input)
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.raster)
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.raster + '_null')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.raster + '_without_topology')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.raster + '_3D')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.raster + '_cover_landcover_1m')
+
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.vector)
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.vector+'_null')
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.vector + '_without_topology')
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.vector + '_3D')
+        cls.runModule('g.remove', type='vector', flags='f', name=cls.vector + '_cover_landcover_1m')
+
+    def test_random_raster(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', input=self.input, npoints=self.npoints, raster=self.raster)
+        # check if random raster was created
+        self.assertRasterExists(self.raster, msg="landcover_1m_raster_random was not created")
+
+    def test_random_vector(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', input=self.input, npoints=self.npoints, vector=self.vector)
+        # check if random vector was created
+        self.assertVectorExists(self.vector, msg="landcover_1m_vector_random was not created")
+        topology = dict(points=20,primitives=20)
+        self.assertVectorFitsTopoInfo(vector=self.vector, reference=topology)
+
+    def test_random_raster_flag_z(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', flags='z', input=self.input, npoints=self.npoints, raster=self.raster+'_null')
+        # check if random raster ( with NULL values )  was created
+        self.assertRasterExists(self.raster, msg="landcover_1m_raster_random_null was not created")
+
+
+    def test_vector_random_flag_z(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', flags='z', input=self.input, npoints=self.npoints, vector=self.vector+'_null')
+        # check if random vector ( with NULL values ) was created
+        self.assertVectorExists(self.vector+'_null', msg="landcover_1m_vector_random_null was not created")
+        topology = dict(points=20,primitives=20)
+        self.assertVectorFitsTopoInfo(vector=self.vector+'_null', reference=topology)
+
+    def test_random_raster_flag_b(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', flags='b', input=self.input, npoints=self.npoints, raster=self.raster+'_without_topology')
+        # check if random raster ( without topology )  was created
+        self.assertRasterExists(self.raster, msg="landcover_1m_raster_random_without_topologywas not created")
+
+    def test_vector_random_flag_b(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', flags='b', input=self.input, npoints=self.npoints, vector=self.vector+'_without_topology')
+        # check if random vector ( without topology ) was created
+        self.assertVectorExists(self.vector+'_without_topology', msg="landcover_1m_vector_random_without_topology was not created")
+        topology = dict(points=20,primitives=20)
+        self.assertVectorFitsTopoInfo(vector=self.vector+'_without_topology', reference=topology)
+
+    def test_random_raster_flag_d(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', flags='d', input=self.input, npoints=self.npoints, raster=self.raster+'_3D')
+        # check if random raster ( 3D points )  was created
+        self.assertRasterExists(self.raster, msg="landcover_1m_raster_random_3D not created")
+
+    def test_vector_random_flag_d(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random', flags='d', input=self.input, npoints=self.npoints, vector=self.vector+'_3D')
+        # check if random vector ( 3D points ) was created
+        self.assertVectorExists(self.vector+'_3D', msg="landcover_1m_vector_random_3D was not created")
+        topology = dict(points=20,primitives=20)
+        self.assertVectorFitsTopoInfo(vector=self.vector+'_3D', reference=topology)
+
+
+    def test_random_raster_cover(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random',input='landuse96_28m', npoints=self.npoints, cover='landcover_1m', raster=self.raster+'_cover_landcover_1m')
+        # check if random raster ( 3D points )  was created
+        self.assertRasterExists(self.raster+'_cover_landcover_1m', msg="landcover_1m_raster_random_cover_landcover_1m was not created")
+
+    def test_vector_random_flag_d(self):
+        """Testing r.random  runs successfully"""
+        self.assertModule('r.random',input='landuse96_28m', npoints=self.npoints, cover='landcover_1m', vector=self.vector+'_cover_landcover_1m')
+        # check if random vector ( 3D points ) was created
+        self.assertVectorExists(self.vector+'_cover_landcover_1m', msg="landcover_1m_vector_cover_landcover_1m was not created")
+        topology = dict(points=20, primitives=20)
+        self.assertVectorFitsTopoInfo(vector=self.vector+'_cover_landcover_1m', reference=topology)
+
+
+if __name__ == '__main__':
+    test()

Added: grass/trunk/raster/r.random/testsuite/testrandom.py
===================================================================
--- grass/trunk/raster/r.random/testsuite/testrandom.py	                        (rev 0)
+++ grass/trunk/raster/r.random/testsuite/testrandom.py	2019-03-13 07:12:18 UTC (rev 74229)
@@ -0,0 +1,75 @@
+"""
+Name:       r.random test
+Purpose:    Tests r.to.vect and its flags/options.
+	
+Author:     Sunveer Singh, Google Code-in 2018
+Copyright:  (C) 2017 by Sunveer Singh and the GRASS Development Team
+Licence:    This program is free software under the GNU General Public
+	            License (>=v2). Read the file COPYING that comes with GRASS
+	            for details.
+"""
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+from grass.gunittest.gmodules import SimpleModule
+
+class Testrr(TestCase):
+    input='lakes'
+    cover="elevation"
+    raster="routfile"
+    vector="voutfile"
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+        cls.runModule('g.region', raster=cls.input) 
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+    
+    def tearDown(self):
+	"""Remove the vector map after each test method"""
+	self.runModule('g.remove', flags='f', type='vector', name=self.vector)
+	self.runModule('g.remove', flags='f', type='raster', name=self.raster)
+
+    def test_flag_z(self):
+        """Testing flag z"""
+        string="""area_cat|count|sum
+        1|0|null
+        2|0|null
+        3|0|null
+        4|0|null
+        5|0|null
+        6|0|null
+        7|0|null
+        8|0|null
+        9|1|7
+        10|0|null
+        """
+        r_random = SimpleModule('r.random', input=self.input, cover=self.cover, npoints=100, vector=self.vector, flags='z')
+        r_random.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=r_random.outputs.stdout)
+
+    def test_flag_i(self):
+        """Testing flag i"""
+        self.assertModule('r.random', input=self.input, cover=self.cover, npoints=100, flags='i')
+
+    def test_flag_d(self):
+        """Testing flag d"""
+        self.assertModule('r.random', input=self.input, cover=self.cover, npoints=100, vector=self.vector, flags='d')
+        self.assertModule('v.info', map=self.vector, flags='t')
+        topology = dict(points=100, lines=0, areas=0, map3d=1)
+	self.assertVectorFitsTopoInfo(self.vector, topology)  
+
+    def test_flag_b(self):
+        """Testing flag b"""
+        self.assertModule('r.random', input=self.input, cover=self.cover, npoints=36011, vector=self.vector, flags='b')
+        self.assertModule('v.info', map=self.vector, flags='t') 
+        topology = dict(points=36011, lines=0, areas=0)
+	self.assertVectorFitsTopoInfo(self.vector, topology) 
+        
+
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()



More information about the grass-commit mailing list