test_pivot.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. '''
  2. Created on 6 dec. 2016
  3. @author: olinox
  4. '''
  5. import unittest
  6. from pypog import geometry
  7. class Test(unittest.TestCase):
  8. def test_pivot_errors(self):
  9. # invalid cell shape
  10. self.assertRaises(ValueError, geometry.pivot, 0, (0,0), [(0,0)], 1)
  11. self.assertRaises(TypeError, geometry.pivot, 0, "a" , [(0,0)], 1)
  12. self.assertRaises(ValueError, geometry.pivot, 0, ("a",0), [(0,0)], 1)
  13. self.assertRaises(TypeError, geometry.pivot, 0, (0,0), 0, 1)
  14. self.assertRaises(ValueError, geometry.pivot, 0, (0,0), ["a", (0,0)], 1)
  15. self.assertRaises(ValueError, geometry.pivot, 0, (0,0), [("a",0), (0,0)], 1)
  16. self.assertRaises(TypeError, geometry.pivot, 0, (0,0), 1, "a")
  17. def test_hex_pivot(self):
  18. """ pivot on hexagonal grid """
  19. attended = [
  20. [(5, 5), (4, 5), (6, 6)],
  21. [(5, 6), (4, 7), (6, 6)],
  22. [(6, 7), (6, 8), (6, 6)],
  23. [(7, 6), (8, 7), (6, 6)],
  24. [(7, 5), (8, 5), (6, 6)],
  25. [(6, 5), (6, 4), (6, 6)],
  26. [(5, 5), (4, 5), (6, 6)]
  27. ]
  28. for i in range( len(attended) ):
  29. self.assertCountEqual(geometry.pivot( geometry.HEX, (6,6), [(6,6)], i), [(6,6)])
  30. result = geometry.pivot(geometry.HEX, (6,6), [(5,5), (4,5), (6,6)], i)
  31. self.assertCountEqual(result, attended[i])
  32. def test_squ_pivot(self):
  33. """ pivot on square grid """
  34. attended = [
  35. [(6, 6), (6, 5), (5, 5), (5, 6)],
  36. [(6, 6), (5, 6), (5, 7), (6, 7)],
  37. [(6, 6), (6, 7), (7, 7), (7, 6)],
  38. [(6, 6), (7, 6), (7, 5), (6, 5)],
  39. [(6, 6), (6, 5), (5, 5), (5, 6)]
  40. ]
  41. for i in range( len(attended) ):
  42. self.assertCountEqual(geometry.pivot( geometry.SQUARE, (6,6), [(6,6)], i), [(6,6)])
  43. result = geometry.pivot(geometry.SQUARE, (6,6), [(6,6), (6,5), (5,5), (5,6)], i)
  44. self.assertCountEqual(result, attended[i])
  45. if __name__ == "__main__":
  46. unittest.main()