test_r3_mapcalc.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from grass.gunittest.case import TestCase
  2. from grass.gunittest.main import test
  3. # TODO: add more expressions
  4. # TODO: add tests with prepared data
  5. class TestBasicOperations(TestCase):
  6. # TODO: replace by unified handing of maps
  7. to_remove = []
  8. @classmethod
  9. def setUpClass(cls):
  10. cls.use_temp_region()
  11. cls.runModule('g.region',
  12. n=85, s=5, e=85, w=5,
  13. b=0, t=2000,
  14. res=1, res3=1)
  15. @classmethod
  16. def tearDownClass(cls):
  17. cls.del_temp_region()
  18. if cls.to_remove:
  19. cls.runModule('g.remove', flags='f', type='raster_3d',
  20. name=','.join(cls.to_remove), verbose=True)
  21. def test_difference_of_the_same_map_double(self):
  22. """Test zero difference of map with itself"""
  23. self.runModule('r3.mapcalc', flags='s',
  24. expression='a = rand(1.0, 200)')
  25. self.to_remove.append('a')
  26. self.assertModule('r3.mapcalc',
  27. expression='diff_a_a = a - a')
  28. self.to_remove.append('diff_a_a')
  29. self.assertRaster3dMinMax('diff_a_a', refmin=0, refmax=0)
  30. def test_difference_of_the_same_map_float(self):
  31. """Test zero difference of map with itself"""
  32. self.runModule('r3.mapcalc', flags='s',
  33. expression='af = rand(float(1), 200)')
  34. self.to_remove.append('af')
  35. self.assertModule('r3.mapcalc',
  36. expression='diff_af_af = af - af')
  37. self.to_remove.append('diff_af_af')
  38. self.assertRaster3dMinMax('diff_af_af', refmin=0, refmax=0)
  39. def test_difference_of_the_same_expression(self):
  40. """Test zero difference of two same expressions"""
  41. self.assertModule('r3.mapcalc',
  42. expression='diff_e_e = 3 * x() * y() * z() - 3 * x() * y() * z()')
  43. self.to_remove.append('diff_e_e')
  44. self.assertRaster3dMinMax('diff_e_e', refmin=0, refmax=0)
  45. def test_nrows_ncols_ndepths_sum(self):
  46. """Test if sum of nrows, ncols and ndepths matches one
  47. expected from current region settigs"""
  48. self.assertModule('r3.mapcalc',
  49. expression='nrows_ncols_ndepths_sum = nrows() + ncols() + ndepths()')
  50. self.to_remove.append('nrows_ncols_ndepths_sum')
  51. self.assertRaster3dMinMax('nrows_ncols_ndepths_sum', refmin=2160, refmax=2160)
  52. if __name__ == '__main__':
  53. test()