test_zone.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. '''
  2. Created on 20 nov. 2016
  3. @author: olinox
  4. '''
  5. import unittest
  6. from core import constants
  7. from core.geometry import gzone
  8. class Test(unittest.TestCase):
  9. """ test the zone algorithm """
  10. def test_hex_zone(self):
  11. """ test the zone algo for hexagonal grid """
  12. geometry = constants.HEX
  13. self.assertCountEqual( gzone.zone( geometry, 3, 3, 0 ), [(3,3)])
  14. self.assertCountEqual( gzone.zone( geometry, 3, 3, 1 ), [(3, 2), (2, 3), (3, 3), (4, 3), (4, 4), (3, 4), (2, 4)])
  15. self.assertCountEqual( gzone.zone( geometry, 3, 3, 2 ), [(3, 2), (1, 3), (5, 4), (4, 5), (1, 4), (2, 3), (4, 2), \
  16. (2, 5), (5, 3), (1, 2), (3, 5), (3, 3), (4, 4), (3, 1), \
  17. (4, 3), (2, 2), (3, 4), (2, 4), (5, 2)] )
  18. def test_squ_zone(self):
  19. """ test the zone algo for square grid """
  20. geometry = constants.SQUARE
  21. self.assertCountEqual( gzone.zone( geometry, 3, 3, 0 ), [(3,3)])
  22. self.assertCountEqual( gzone.zone( geometry, 3, 3, 1 ), [(3, 2), (3, 3), (4, 4), (2, 3), (4, 3), (2, 2), (4, 2), (3, 4), (2, 4)])
  23. self.assertCountEqual( gzone.zone( geometry, 3, 3, 2 ), [(2, 4), (3, 2), (5, 4), (1, 3), (4, 5), (2, 1), (1, 4), (2, 3), (4, 2), \
  24. (5, 1), (2, 5), (3, 5), (5, 3), (1, 2), (3, 3), (5, 5), (4, 4), (3, 1), \
  25. (1, 5), (4, 3), (2, 2), (4, 1), (5, 2), (3, 4), (1, 1)])
  26. def test_errors(self):
  27. """test the errors due to bad parameters"""
  28. self.assertRaises( TypeError, gzone.zone, 5, 0, 0, "a")
  29. self.assertRaises( TypeError, gzone.zone, 5, "a", 0, 1)
  30. self.assertRaises( TypeError, gzone.zone, 5, 0, "a", 1)
  31. self.assertRaises( ValueError, gzone.zone, 5, 0, 0, -1)
  32. self.assertRaises( ValueError, gzone.zone, -1, 0, 0, 1)
  33. self.assertRaises( ValueError, gzone.zone, "a", 0, 0, 1)
  34. if __name__ == "__main__":
  35. unittest.main()