| 
				
			 | 
			
			
				@@ -0,0 +1,128 @@ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				1
			 | 
			
			
				+from os import getcwd 
			 | 
		
	
		
			
			| 
				
			 | 
			
				2
			 | 
			
			
				+from sys import path as ppath 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+from intelligine.core.exceptions import NoPheromone 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+ppath.insert(1,getcwd()+'/modules') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				6
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+from intelligine.synergy.object.Food import Food 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+from intelligine.tests.simulation.mode.Base import Base 
			 | 
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				+from intelligine.synergy.Colony import Colony 
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+from intelligine.synergy.Simulation import Simulation 
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+from intelligine.synergy.ColonyConfiguration import ColonyConfiguration 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+from intelligine.synergy.event.move.MoveAction import MoveAction 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+from intelligine.synergy.event.move.direction import NORTH, SOUTH 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+from intelligine.tests.src.event.MoveAction import MoveAction as TestMoveAction 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+from synergine.synergy.collection.SynergyCollection import SynergyCollection 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+from synergine.synergy.collection.Configuration import Configuration 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+from intelligine.core.Context import Context 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, MOVE_MODE 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+from intelligine.cst import PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+class TestChangeMode(Base): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+    def __init__(self, methodName='runTest'): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+        super().__init__(methodName) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+        self.ant = None 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+        self.food = None 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+        self._force_move = self._force_move 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+    @staticmethod 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    def _force_move(self_move_action, context, object_point): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+        object_movement_mode = context.metas.value.get(MOVE_MODE, self_move_action._object_id) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+        if object_movement_mode == MOVE_MODE_GOHOME: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+            return SOUTH 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+        return NORTH 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+    def _get_set_up_simulation(self): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+        return Simulation([self._get_colony(), self._get_foods()]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+    def _get_colony(self): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+        test_case = self 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+        class TestColony(Colony): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+            def __init__(self, configuration): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+                super().__init__(configuration) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+                self._actions.remove(MoveAction) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+                TestMoveAction.force_direction = test_case._force_move 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+                self._actions.append(TestMoveAction) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+        return TestColony(self._get_colony_configuration()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+    def _get_colony_configuration(self): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+        test_case = self 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+        class TestColonyConfiguration(ColonyConfiguration): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+            _start_position = (0, 0, 0) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+            _ant_count = 1 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+            def get_start_objects(self, collection, context): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+                ants = super().get_start_objects(collection, context) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+                test_case.ant = ants[0] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+                return ants 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+        return TestColonyConfiguration() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+    def _get_foods(self): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+        class Foods(SynergyCollection): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+            pass 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+        return Foods(self._get_food_configuration()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+    def _get_food_configuration(self): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+        test_case = self 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+        class FoodConfiguration(Configuration): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+            def get_start_objects(self, collection, context): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+                food = Food(collection, context) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+                food.set_position((0, 0, -3)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+                test_case.food = food 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+                return [food] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+        return FoodConfiguration() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+    def _get_core_configuration(self, cycles, main_process=True): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+        config = super()._get_core_configuration(cycles, main_process) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+        config.update({ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+            'app': { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+                'classes': { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+                    'Context': Context 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+                } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				+        }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+        return config 
			 | 
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				88
			 | 
			
			
				+    def test_from_exploration_to_go_home(self): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				89
			 | 
			
			
				+        self._run_and_get_core(0) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				90
			 | 
			
			
				+        self.assertEquals((0, 0, 0), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				91
			 | 
			
			
				+        self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+        self._run_and_get_core(1) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+        self.assertEquals((0, 0, -1), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				95
			 | 
			
			
				+        self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				96
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				97
			 | 
			
			
				+        self._run_and_get_core(2) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				98
			 | 
			
			
				+        self.assertEquals((0, 0, -2), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				99
			 | 
			
			
				+        self.assertEquals((PHEROMON_DIR_HOME, 2), 
			 | 
		
	
		
			
			| 
				
			 | 
			
				100
			 | 
			
			
				+                          self.ant.get_movement_pheromone_gland().get_movement_molecules()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				101
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+        # Ant has take Food piece 
			 | 
		
	
		
			
			| 
				
			 | 
			
				103
			 | 
			
			
				+        self._run_and_get_core(3) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				104
			 | 
			
			
				+        self.assertEquals((0, 0, -3), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				106
			 | 
			
			
				+        self.assertTrue(self.ant.is_carrying()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				107
			 | 
			
			
				+        self.assertIsNotNone(self.ant.get_carried()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				108
			 | 
			
			
				+        self.assertEquals(self.food.__class__, self.ant.get_carried().__class__) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				109
			 | 
			
			
				+        self.assertEquals(MOVE_MODE_GOHOME, self.ant.get_brain().get_movement_mode()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				110
			 | 
			
			
				+        # Now it appose exploration pheromone 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+        self.assertEquals((PHEROMON_DIR_EXPLO, 0), 
			 | 
		
	
		
			
			| 
				
			 | 
			
				112
			 | 
			
			
				+                          self.ant.get_movement_pheromone_gland().get_movement_molecules()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				113
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				114
			 | 
			
			
				+        self._run_and_get_core(4) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				115
			 | 
			
			
				+        self.assertEquals((0, 0, -2), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				+        self._run_and_get_core(5) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				118
			 | 
			
			
				+        self.assertEquals((0, 0, -1), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				119
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				120
			 | 
			
			
				+        self._run_and_get_core(6) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				121
			 | 
			
			
				+        self.assertEquals((0, 0, 0), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				122
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				123
			 | 
			
			
				+        # Ant has put his food piece 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+        self._run_and_get_core(7) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				+        self.assertEquals((0, 0, -1), self.ant.get_position()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				126
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+        self.assertFalse(self.ant.is_carrying()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+        self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode()) 
			 |