Browse Source

Thirst test on pheromone directions

Bastien Sevajol 9 years ago
parent
commit
5246d7267c

+ 5 - 0
intelligine/tests/simulation/pheromone/Base.py View File

@@ -0,0 +1,5 @@
1
+import unittest
2
+
3
+
4
+class Base(unittest.TestCase):
5
+    pass

+ 81 - 0
intelligine/tests/simulation/pheromone/TestDirection.py View File

@@ -0,0 +1,81 @@
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
+
6
+from intelligine.tests.simulation.pheromone.Base import Base
7
+from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
8
+from intelligine.core.Context import Context
9
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO
10
+
11
+
12
+class TestDirection(Base):
13
+
14
+    def __init__(self, *args, **kwargs):
15
+        super().__init__(*args, **kwargs)
16
+        self._context = Context()
17
+
18
+    def setUp(self):
19
+        self._context = Context()
20
+
21
+    def _set_up_pheromones(self, pheromones, re_init=True):
22
+        if re_init:
23
+            self._context = Context()
24
+        for position in pheromones:
25
+            self._context.pheromones().set_pheromones(position, pheromones[position])
26
+
27
+    def _test_direction(self, pheromones, direction, pheromone_type=PHEROMON_DIR_EXPLO, reference_point=(0, 0, 0)):
28
+        """
29
+
30
+        :param pheromones:
31
+        :param direction:
32
+        :param pheromone_type:
33
+        :param reference_point:
34
+        :return: void
35
+        """
36
+        self._set_up_pheromones(pheromones)
37
+        direction_tested = DirectionPheromone.get_direction_for_point(self._context, reference_point, pheromone_type)
38
+        self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
39
+
40
+    def test_direct_route(self):
41
+        """
42
+        Test easy direction with 1 best pheromones just near actual position
43
+        :return:
44
+        """
45
+        test_data = {
46
+            10: {
47
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
48
+                (0, -1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
49
+            },
50
+            11: {
51
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
52
+                (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
53
+            },
54
+            12: {
55
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
56
+                (0, 1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
57
+            },
58
+            13: {
59
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
60
+                (0, -1, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
61
+            },
62
+            15: {
63
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
64
+                (0, 1, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
65
+            },
66
+            16: {
67
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
68
+                (0, -1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
69
+            },
70
+            17: {
71
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
72
+                (0, 0, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
73
+            },
74
+            18: {
75
+                (0, 0, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1)}},
76
+                (0, 1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1)}}
77
+            }
78
+        }
79
+
80
+        for direction_wanted in test_data:
81
+            self._test_direction(test_data[direction_wanted], direction_wanted)