v_univar_test.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. """
  2. Name: v.univar test
  3. Purpose: Tests v.univar and its flags/options.
  4. Author: Sunveer Singh, Google Code-in 2017
  5. Copyright: (C) 2017 by Sunveer Singh and the GRASS Development Team
  6. Licence: This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. """
  10. from grass.gunittest.case import TestCase
  11. from grass.gunittest.main import test
  12. from grass.gunittest.gmodules import SimpleModule
  13. class TestProfiling(TestCase):
  14. def test_flagg(self):
  15. """Testing flag g with map lakes"""
  16. output_str = u"""n=15279
  17. nmissing=0
  18. nnull=0
  19. min=1
  20. max=15279
  21. range=15278
  22. sum=1.16732e+08
  23. mean=7640
  24. mean_abs=7640
  25. population_stddev=4410.67
  26. population_variance=1.9454e+07
  27. population_coeff_variation=0.577312
  28. sample_stddev=4410.81
  29. sample_variance=1.94553e+07
  30. kurtosis=-1.20024
  31. skewness=-2.41826e-14"""
  32. v_univar = SimpleModule("v.univar", flags="g", map='lakes', column='cat')
  33. v_univar.run()
  34. self.assertLooksLike(actual=v_univar.outputs.stdout,
  35. reference=output_str)
  36. def test_flage(self):
  37. """Testing flag e with map geology"""
  38. output_str = u"""number of features with non NULL attribute: 1832
  39. number of missing attributes: 0
  40. number of NULL attributes: 0
  41. minimum: 166.947
  42. maximum: 2.72948e+06
  43. range: 2.72932e+06
  44. sum: 7.88761e+07
  45. mean: 43054.7
  46. mean of absolute values: 43054.7
  47. population standard deviation: 132689
  48. population variance: 1.76064e+10
  49. population coefficient of variation: 3.08187
  50. sample standard deviation: 132725
  51. sample variance: 1.7616e+10
  52. kurtosis: 139.157
  53. skewness: 9.7065
  54. 1st quartile: 3699.32
  55. median (even number of cells): 10308.4
  56. 3rd quartile: 29259.1
  57. 90th percentile: 86449.7"""
  58. v_univar = SimpleModule('v.univar', map='geology', column='PERIMETER', flags='e')
  59. v_univar.run()
  60. self.assertLooksLike(actual=v_univar.outputs.stdout,
  61. reference=output_str)
  62. def test_flagw(self):
  63. """Testing flag w with map lakes"""
  64. output_str = u"""number of features with non NULL attribute: 15279
  65. number of missing attributes: 0
  66. number of NULL attributes: 0
  67. minimum: 2
  68. maximum: 15280
  69. range: 15278
  70. sum: 5.76349e+11
  71. mean: 6190.76
  72. mean of absolute values: 6190.76"""
  73. v_univar = SimpleModule('v.univar', map='lakes', column='FULL_HYDRO', flags='w')
  74. v_univar.run()
  75. self.assertLooksLike(actual=v_univar.outputs.stdout,
  76. reference=output_str)
  77. def test_flagd(self):
  78. """Testing flag d with map hospitals"""
  79. univar_string = u"""number of primitives: 160
  80. number of non zero distances: 12561
  81. number of zero distances: 0
  82. minimum: 9.16773
  83. maximum: 760776
  84. range: 760767
  85. sum: 2.69047e+09
  86. mean: 214193
  87. mean of absolute values: 214193
  88. population standard deviation: 128505
  89. population variance: 1.65136e+10
  90. population coefficient of variation: 0.599953
  91. sample standard deviation: 128511
  92. sample variance: 1.6515e+10
  93. kurtosis: 0.277564
  94. skewness: 0.801646"""
  95. v_univar = SimpleModule('v.univar', map='hospitals', column='CITY', flags='d')
  96. v_univar.run()
  97. self.assertLooksLike(actual=v_univar.outputs.stdout,
  98. reference=univar_string)
  99. def test_output(self):
  100. """Testing output of v.univar"""
  101. univar_string="""n=160
  102. min=1
  103. max=160
  104. range=159
  105. mean=80.5
  106. sum=12880"""
  107. self.assertVectorFitsUnivar(map='hospitals', column='cat', reference=univar_string, precision=3)
  108. def test_output2(self):
  109. """Testing output of v.univar"""
  110. univar_string="""n=357
  111. min=1
  112. max=357
  113. range=356
  114. mean=179.82
  115. sum=63836"""
  116. self.assertVectorFitsUnivar(map='roadsmajor', column='MAJORRDS_', reference=univar_string, precision=3)
  117. if __name__ == '__main__':
  118. test()