1""" 2Name: v.vect.stats test 3Purpose: Tests v.vect.stats and its flags/options. 4 5Author: Sunveer Singh, Google Code-in 2017 6Copyright: (C) 2017 by Sunveer Singh and the GRASS Development Team 7Licence: This program is free software under the GNU General Public 8 License (>=v2). Read the file COPYING that comes with GRASS 9 for details. 10""" 11from grass.gunittest.case import TestCase 12from grass.gunittest.main import test 13from grass.gunittest.gmodules import SimpleModule 14 15class Testrr(TestCase): 16 input='hospitals' 17 areas='zipcodes_wake' 18 19 @classmethod 20 def setUpClass(cls): 21 cls.use_temp_region() 22 23 @classmethod 24 def tearDownClass(cls): 25 cls.del_temp_region() 26 27 def test_sum(self): 28 """Testing method sum""" 29 string="""area_cat|count|sum 30 1|0|null 31 2|0|null 32 3|0|null 33 4|0|null 34 5|0|null 35 6|0|null 36 7|0|null 37 8|0|null 38 9|1|7 39 10|0|null 40 """ 41 v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='sum', count_column='num_points', 42 stats_column='avg_elev', points_column='cat') 43 v_vect_stats.outputs.stdout= string 44 self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout) 45 46 47 def test_average(self): 48 """Testing method average""" 49 string="""area_cat|count|average 50 1|1|2681 51 2|0|null 52 3|2|3958.5 53 4|0|null 54 5|0|null 55 6|8|4012 56 7|7|4185.42857142857 57 8|19|4396.78947368421 58 9|4|4222 59 10|3|4400.33333333333 60 """ 61 v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='average', count_column='num_points', 62 stats_column='avg_elev', points_column='cat') 63 v_vect_stats.outputs.stdout= string 64 self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout) 65 66 def test_median(self): 67 """Testing method variance""" 68 string="""area_cat|count|variance 69 1|1|0 70 2|0|null 71 3|2|702.25 72 4|0|null 73 5|0|null 74 6|8|7639 75 7|7|2661.38775510204 76 8|19|69198.7977839335 77 9|4|42.5 78 10|3|3968.22222222222 79 """ 80 v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='variance', count_column='num_points', 81 stats_column='avg_elev', points_column='cat') 82 v_vect_stats.outputs.stdout= string 83 self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout) 84 85 def test_mincat(self): 86 """Testing method min_cat""" 87 string="""area_cat|count|range 88 1|1|0 89 2|0|null 90 3|2|53 91 4|0|null 92 5|0|null 93 6|8|255 94 7|7|168 95 8|19|892 96 9|4|17 97 10|3|152 98 """ 99 v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='range', count_column='num_points', 100 stats_column='avg_elev', points_column='cat') 101 v_vect_stats.outputs.stdout= string 102 self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout) 103 104 def test_maxcat(self): 105 """Testing method max_cat""" 106 string="""area_cat|count|max_cat 107 1|0|null 108 2|0|null 109 3|0|null 110 4|0|null 111 5|0|null 112 6|0|null 113 7|0|null 114 8|0|null 115 9|1|7 116 10|0|null 117 """ 118 v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='max_cat', count_column='num_points', 119 stats_column='avg_elev', points_column='cat') 120 v_vect_stats.outputs.stdout= string 121 self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout) 122 123 def test_mode(self): 124 """Testing method mode """ 125 string="""area_cat|count|mode 126 1|0|null 127 2|0|null 128 3|0|null 129 4|0|null 130 5|0|null 131 6|0|null 132 7|0|null 133 8|0|null 134 9|1|7 135 10|0|null 136 """ 137 v_vect_stats = SimpleModule('v.vect.stats', points=self.input, areas=self.areas, method='mode', count_column='num_points', 138 stats_column='avg_elev', points_column='cat') 139 v_vect_stats.outputs.stdout= string 140 self.assertLooksLike(reference=string, actual=v_vect_stats.outputs.stdout) 141 142if __name__ == '__main__': 143 test() 144