TestDirection.py 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from os import getcwd
  2. from sys import path as ppath
  3. ppath.insert(1,getcwd()+'/modules') # TODO: win32 compatibilite (python path)
  4. # TODO: load et launch des tests auto (avec bootstrap contenant ci dessus)
  5. from intelligine.tests.simulation.pheromone.Base import Base
  6. from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
  7. from intelligine.core.Context import Context
  8. from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO
  9. class TestDirection(Base):
  10. def __init__(self, *args, **kwargs):
  11. super().__init__(*args, **kwargs)
  12. self._context = Context()
  13. def setUp(self):
  14. self._context = Context()
  15. def _set_up_pheromones(self, pheromones, re_init=True):
  16. if re_init:
  17. self._context = Context()
  18. for position in pheromones:
  19. self._context.pheromones().set_pheromones(position, pheromones[position])
  20. def _test_direction(self, pheromones, direction, pheromone_type=PHEROMON_DIR_EXPLO, reference_point=(0, 0, 0)):
  21. """
  22. :param pheromones:
  23. :param direction:
  24. :param pheromone_type:
  25. :param reference_point:
  26. :return: void
  27. """
  28. self._set_up_pheromones(pheromones)
  29. direction_tested = DirectionPheromone.get_direction_for_point(self._context, reference_point, pheromone_type)
  30. self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
  31. def test_direct_route(self):
  32. """
  33. Test easy direction with 1 best pheromones just near actual position
  34. :return:
  35. """
  36. test_data = {
  37. 10: {
  38. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  39. (0, -1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  40. },
  41. 11: {
  42. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  43. (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  44. },
  45. 12: {
  46. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  47. (0, 1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  48. },
  49. 13: {
  50. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  51. (0, -1, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  52. },
  53. 15: {
  54. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  55. (0, 1, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  56. },
  57. 16: {
  58. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  59. (0, -1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  60. },
  61. 17: {
  62. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  63. (0, 0, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  64. },
  65. 18: {
  66. (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
  67. (0, 1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
  68. }
  69. }
  70. for direction_wanted in test_data:
  71. self._test_direction(test_data[direction_wanted], direction_wanted)