[GRASS-SVN] r72097 - in grass/trunk/vector/v.vect.stats: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 18 08:23:18 PST 2018


Author: lucadelu
Date: 2018-01-18 08:23:18 -0800 (Thu, 18 Jan 2018)
New Revision: 72097

Added:
   grass/trunk/vector/v.vect.stats/testsuite/
   grass/trunk/vector/v.vect.stats/testsuite/test_vect_stats.py
Log:
v.vect.stats: added tests, thanks to Sunveer Singh during Google Code-in 2017

Added: grass/trunk/vector/v.vect.stats/testsuite/test_vect_stats.py
===================================================================
--- grass/trunk/vector/v.vect.stats/testsuite/test_vect_stats.py	                        (rev 0)
+++ grass/trunk/vector/v.vect.stats/testsuite/test_vect_stats.py	2018-01-18 16:23:18 UTC (rev 72097)
@@ -0,0 +1,143 @@
+"""
+Name:       v.vect.stats test
+Purpose:    Tests v.vect.stats and its flags/options.
+	
+Author:     Sunveer Singh, Google Code-in 2017
+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='hospitals'
+    areas='zipcodes_wake'
+
+    @classmethod
+    def setUpClass(cls):
+        cls.use_temp_region()
+	
+    @classmethod
+    def tearDownClass(cls):
+        cls.del_temp_region()
+
+    def test_sum(self):
+        """Testing method sum"""
+        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
+        """
+        v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='sum', count_column='num_points', 
+                                    stats_column='avg_elev', points_column='cat')
+        v_vect_stats.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout)
+
+
+    def test_average(self):
+        """Testing method average"""
+        string="""area_cat|count|average
+        1|1|2681
+        2|0|null
+        3|2|3958.5
+        4|0|null
+        5|0|null
+        6|8|4012
+        7|7|4185.42857142857
+        8|19|4396.78947368421
+        9|4|4222
+        10|3|4400.33333333333
+        """
+        v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='average', count_column='num_points', 
+                                    stats_column='avg_elev', points_column='cat')
+        v_vect_stats.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout)
+
+    def test_median(self):
+        """Testing method variance"""
+        string="""area_cat|count|variance
+        1|1|0
+        2|0|null
+        3|2|702.25
+        4|0|null
+        5|0|null
+        6|8|7639
+        7|7|2661.38775510204
+        8|19|69198.7977839335
+        9|4|42.5
+        10|3|3968.22222222222
+        """
+        v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='variance', count_column='num_points', 
+                                    stats_column='avg_elev', points_column='cat')
+        v_vect_stats.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout)
+        
+    def test_mincat(self):
+        """Testing method min_cat"""
+        string="""area_cat|count|range
+        1|1|0
+        2|0|null
+        3|2|53
+        4|0|null
+        5|0|null
+        6|8|255
+        7|7|168
+        8|19|892
+        9|4|17
+        10|3|152
+        """ 
+        v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='range', count_column='num_points', 
+                                    stats_column='avg_elev', points_column='cat')
+        v_vect_stats.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout)
+
+    def test_maxcat(self):
+        """Testing method max_cat"""
+        string="""area_cat|count|max_cat
+        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
+        """
+        v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='max_cat', count_column='num_points', 
+                                    stats_column='avg_elev', points_column='cat')
+        v_vect_stats.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout)
+
+    def test_mode(self):
+        """Testing method mode """
+        string="""area_cat|count|mode
+        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
+        """
+        v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='mode', count_column='num_points', 
+                                    stats_column='avg_elev', points_column='cat')
+        v_vect_stats.outputs.stdout= string
+        self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout)
+
+if __name__ == '__main__':
+    test()


Property changes on: grass/trunk/vector/v.vect.stats/testsuite/test_vect_stats.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native



More information about the grass-commit mailing list