Browse Source

Add tests pheromones

Bastien Sevajol 9 years ago
parent
commit
ec3c0fa1ce
1 changed files with 41 additions and 7 deletions
  1. 41 7
      intelligine/tests/simulation/pheromone/TestDirection.py

+ 41 - 7
intelligine/tests/simulation/pheromone/TestDirection.py View File

1
 from os import getcwd
1
 from os import getcwd
2
 from sys import path as ppath
2
 from sys import path as ppath
3
+from intelligine.core.exceptions import NoPheromone
4
+
3
 ppath.insert(1,getcwd()+'/modules') # TODO: win32 compatibilite (python path)
5
 ppath.insert(1,getcwd()+'/modules') # TODO: win32 compatibilite (python path)
4
 # TODO: load et launch des tests auto (avec bootstrap contenant ci dessus)
6
 # TODO: load et launch des tests auto (avec bootstrap contenant ci dessus)
5
 
7
 
6
 from intelligine.tests.simulation.pheromone.Base import Base
8
 from intelligine.tests.simulation.pheromone.Base import Base
7
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
9
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
8
 from intelligine.core.Context import Context
10
 from intelligine.core.Context import Context
9
-from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO
11
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, PHEROMON_DIR_HOME
10
 
12
 
11
 
13
 
12
 class TestDirection(Base):
14
 class TestDirection(Base):
141
         test_data = {
143
         test_data = {
142
             11: {
144
             11: {
143
                 (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2)}}
145
                 (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2)}}
146
+            },
147
+            11: {
148
+                (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2)}},
149
+                (0, -1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 500)}}  # An other pheromone type
144
             }
150
             }
145
         }
151
         }
146
-        self._test_direction_for_points({(0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2)}}},
147
-                                        11)
152
+
153
+        for direction in test_data:
154
+            self._test_direction_for_points(test_data[direction], direction)
148
 
155
 
149
     def test_direction_with_multiple_intensity(self):
156
     def test_direction_with_multiple_intensity(self):
150
-        self._test_direction_for_points({(0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 5)}},
151
-                                         (0, 1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}},
152
-                                         (0, -1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}}},
153
-                                        11)
157
+        test_data = {
158
+            11: {
159
+                (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 5)}},
160
+                (0, 1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}},
161
+                (0, -1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}}
162
+            },
163
+            11: {
164
+                (0, 0, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 5)}},
165
+                (0, -1, 0): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 500)}},  # An other pheromone_type
166
+                (0, 1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}},
167
+                (0, -1, -1): {PHEROMON_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4)}}
168
+            }
169
+        }
170
+
171
+        for direction in test_data:
172
+            self._test_direction_for_points(test_data[direction], direction)
173
+
174
+    def test_no_pheromones_around(self):
175
+        # No pheromone
176
+        try:  # WTF ?
177
+            self.assertRaises(NoPheromone, self._test_direction_for_points({}, -1))
178
+        except NoPheromone:
179
+            self.assertTrue(True)
180
+
181
+        # Wrong pheromone type
182
+        try:  # WTF ?
183
+            self.assertRaises(NoPheromone, self._test_direction_for_points({
184
+                (0, 1, 1): {PHEROMON_DIRECTION: {PHEROMON_DIR_HOME: (9, 5)}}
185
+            }, -1))
186
+        except NoPheromone:
187
+            self.assertTrue(True)