Forráskód Böngészése

r.tile: added tests from GCI 2018

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74230 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 6 éve
szülő
commit
5f988393bc
2 módosított fájl, 123 hozzáadás és 0 törlés
  1. 65 0
      raster/r.tile/testsuite/test_r_tile.py
  2. 58 0
      raster/r.tile/testsuite/testrt.py

+ 65 - 0
raster/r.tile/testsuite/test_r_tile.py

@@ -0,0 +1,65 @@
+"""
+Name:        r.tile test
+Purpose:    Tests r.tile module and the number of created tiles.
+
+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 = 'lakes'
+    output_prefix = 'lakes_tile'
+    width = '1000'
+    height = '1000'
+    overlap = '10'
+
+    @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.output_prefix + '-000-000')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + '-000-001')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + '-001-000')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + '-001-001')
+
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + 'overlap' + '-000-000')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + 'overlap' + '-000-001')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + 'overlap' + '-001-000')
+        cls.runModule('g.remove', type='raster', flags='f', name=cls.output_prefix + 'overlap' + '-001-001')
+
+    def test_raster_tile(self):
+        """Testing r.tile runs successfully"""
+        self.assertModule('r.tile', input=self.input, output=self.output_prefix, width=self.width, height=self.height)
+        # If the above statement executed successful then
+        # 4 rasters tiles with following details should exits
+        self.assertRasterExists(self.output_prefix+'-000-000', msg="lakes_tile-000-000 does not exits")
+        self.assertRasterExists(self.output_prefix+'-000-001', msg="lakes_tile-000-001 does not exits")
+        self.assertRasterExists(self.output_prefix+'-001-000', msg="lakes_tile-001-000 does not exits")
+        self.assertRasterExists(self.output_prefix+'-001-001', msg="lakes_tile-001-001 does not exits")
+
+    def test_raster_tile_overlap(self):
+        """Testing r.tile runs successfully with overlap option"""
+        self.assertModule('r.tile', input=self.input, output=self.output_prefix+'overlap', width=self.width, height=self.height, overlap=self.overlap)
+        # If the above statement executed successful then
+        # 4 rasters tiles with following details should exits
+        self.assertRasterExists(self.output_prefix+'overlap'+'-000-000', msg="lakes_tile-000-000 does not exits")
+        self.assertRasterExists(self.output_prefix+'overlap'+'-000-001', msg="lakes_tile-000-001 does not exits")
+        self.assertRasterExists(self.output_prefix+'overlap'+'-001-000', msg="lakes_tile-001-000 does not exits")
+        self.assertRasterExists(self.output_prefix+'overlap'+'-001-001', msg="lakes_tile-001-001 does not exits")
+
+
+
+
+if __name__ == '__main__':
+    test()

+ 58 - 0
raster/r.tile/testsuite/testrt.py

@@ -0,0 +1,58 @@
+"""
+Name:       r.tile test
+Purpose:    Tests r.tile and its flags/options.
+	
+Author:     Sunveer Singh, Google Code-in 2018
+Copyright:  (C) 2018 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
+
+class Testrr(TestCase):
+    input='elevation'
+    output='tile'
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+        cls.runModule('g.region', raster=cls.input)
+	
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+
+
+    def test_basic(self):
+        """Running a basic test"""
+        self.assertModule('r.tile', input=self.input, output=self.output, width=1500/2, height=1350/2)
+
+    def test_univar(self):
+        """Testing the output map tile-001-002"""
+        string="""min=55.5787925720215
+        n=506250
+        max=144.267288208008"""
+        self.assertModule('r.tile', input=self.input, output=self.output, width=1500/2, height=1350/2)
+        self.assertRasterFitsUnivar('tile-000-001',
+	                            reference=string, precision=2)
+
+    def test_overlap(self):
+        """Testing overlap parameter with output map tile-000-000"""
+        tile="tile-000-000"
+        self.assertModule('r.tile', input=self.input, output=self.output, width=1500/2, height=1350/2, overlap=250)
+        self.assertRasterMinMax(map=tile, refmin=74.75374, refmax=156.3299,
+	                        msg="tile-000-000 in degrees must be between 74.75374 and 156.3299") 
+
+    def test_minmax(self):
+        """Testing output map tile-000-001"""
+        tile1="tile-000-001"
+        self.assertModule('r.tile', input=self.input, output=self.output, width=1500/2, height=1350/2)
+        self.assertRasterMinMax(map=tile1, refmin=55.57879, refmax=144.2673,
+	                        msg="tile-000-001 in degrees must be between 55.57879 and 144.2673")
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()
+