Browse Source

update for tests: put constrain removed when test

Bastien Sevajol 9 years ago
parent
commit
cb127ffc5b

+ 5 - 0
config.py View File

@@ -57,5 +57,10 @@ config = {
57 57
               'color': (125, 125, 125)
58 58
             }
59 59
         }
60
+    },
61
+    'ant': {
62
+        'take': {
63
+            'cant_put_still': 5
64
+        }
60 65
     }
61 66
 }

+ 1 - 1
intelligine/sandbox/exploration/RocksConfiguration.py View File

@@ -31,7 +31,7 @@ class RocksConfiguration(Configuration):
31 31
                         rock.set_position((0, xi, yi))
32 32
                         rocks.append(rock)
33 33
 
34
-        #  TEST
34
+        #  TEST (en attendant d'avoir des algo pour deposer dans un depot)
35 35
         food1 = Food(collection, context)
36 36
         food1.set_position((0, 0, 0))
37 37
         food1.is_takable = lambda: False

+ 1 - 1
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py View File

@@ -47,7 +47,7 @@ class AntPutBrainPart(TakeBrainPart):
47 47
         # TODO: Pour le moment on ne regarde pas si ce sont tous des obj identique
48 48
         count_obj_here = len(context.metas.list.get(POSITIONS, position, allow_empty=True))
49 49
         # TODO: 5 est hardcode; de plus cette cntrainte (not brain) devrait dependre de l'objet, du contexte ...
50
-        if count_obj_here <= 5 and (context.position_is_penetrable(position) or position == (0, 0, 0)):  # TODO TEST !!!
50
+        if count_obj_here <= 5 and (context.position_is_penetrable(position)):  # TODO TEST !!!
51 51
             return True
52 52
         return False
53 53
 

+ 3 - 1
intelligine/synergy/event/transport/TakeableAction.py View File

@@ -1,4 +1,5 @@
1 1
 from intelligine.synergy.event.move.MoveAction import MoveAction
2
+from synergine.core.Core import Core
2 3
 from synergine.synergy.event.Action import Action
3 4
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
4 5
 from intelligine.cst import CANT_PUT_STILL, BRAIN_PART_TAKE
@@ -23,5 +24,6 @@ class TakeableAction(Action):
23 24
         obj_carried = obj_transportable.get_what_carry()
24 25
         obj_carried.set_carried_by(obj)
25 26
         obj.carry(obj_carried)
26
-        context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
27
+        cant_put_still = Core.get_configuration_manager().get('ant.take.cant_put_still')
28
+        context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still)
27 29
         obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj, obj_carried, context)

+ 23 - 12
intelligine/tests/simulation/mode/TestChangeMode.py View File

@@ -68,10 +68,17 @@ class TestChangeMode(Base):
68 68
         test_case = self
69 69
         class FoodConfiguration(Configuration):
70 70
             def get_start_objects(self, collection, context):
71
+                foods = []
71 72
                 food = Food(collection, context)
72 73
                 food.set_position((0, 0, -3))
74
+                #  TEST (en attendant d'avoir des algo pour deposer dans un depot)
75
+                food1 = Food(collection, context)
76
+                food1.set_position((0, 0, -1))
77
+                food1.is_takable = lambda: False
78
+                foods.append(food1)
79
+                foods.append(food)
73 80
                 test_case.food = food
74
-                return [food]
81
+                return foods
75 82
         return FoodConfiguration()
76 83
 
77 84
     def _get_core_configuration(self, cycles, main_process=True):
@@ -81,6 +88,12 @@ class TestChangeMode(Base):
81 88
                 'classes': {
82 89
                     'Context': Context
83 90
                 }
91
+            },
92
+            'ant': {
93
+                'take': {
94
+                    # Disable this constrain to test in little space
95
+                    'cant_put_still': 0
96
+                }
84 97
             }
85 98
         })
86 99
         return config
@@ -89,34 +102,32 @@ class TestChangeMode(Base):
89 102
         self._run_and_get_core(0)
90 103
         self.assertEquals((0, 0, 0), self.ant.get_position())
91 104
         self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
105
+        self.assertFalse(self.ant.is_carrying())
92 106
 
93 107
         self._run_and_get_core(1)
94 108
         self.assertEquals((0, 0, -1), self.ant.get_position())
95 109
         self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
110
+        self.assertFalse(self.ant.is_carrying())
96 111
 
112
+        # Ant has take Food piece
97 113
         self._run_and_get_core(2)
98 114
         self.assertEquals((0, 0, -2), self.ant.get_position())
115
+        self.assertTrue(self.ant.is_carrying())
116
+        self.assertIsNotNone(self.ant.get_carried())
117
+        self.assertEquals(self.food.__class__, self.ant.get_carried().__class__)
99 118
         pheromone = self.ant.get_movement_pheromone_gland().get_pheromone()
119
+        # Now it appose exploration pheromone
100 120
         self.assertEquals((PHEROMON_DIR_EXPLO, 0), (pheromone.get_type(), pheromone.get_distance()))
121
+        self.assertEquals(MOVE_MODE_GOHOME, self.ant.get_brain().get_movement_mode())
122
+        self.assertEquals(PHEROMON_DIR_EXPLO, self.ant.get_movement_pheromone_gland().get_pheromone_type())
101 123
 
102
-        # Ant has take Food piece
103 124
         self._run_and_get_core(3)
104 125
         self.assertEquals((0, 0, -1), self.ant.get_position())
105
-
106 126
         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, self.ant.get_movement_pheromone_gland().get_pheromone_type())
112 127
 
113 128
         self._run_and_get_core(4)
114 129
         self.assertEquals((0, 0, 0), self.ant.get_position())
115
-
116 130
         # Ant has put his food piece
117
-        self._run_and_get_core(5)
118
-        self.assertEquals((0, 0, -1), self.ant.get_position())
119
-
120 131
         self.assertFalse(self.ant.is_carrying())
121 132
         self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
122 133
         self.assertEquals(PHEROMON_DIR_HOME, self.ant.get_movement_pheromone_gland().get_pheromone_type())

+ 4 - 0
tests.py View File

@@ -1,5 +1,9 @@
1 1
 import unittest
2 2
 
3
+from os import getcwd
4
+from sys import path as ppath
5
+ppath.insert(1,getcwd()+'/modules') # TODO: win32 compatibilite (python path)
6
+
3 7
 """
4 8
 python3.4 -m unittest /home/bux/Projets/socialintengine/intelligine/tests/simulation/mode/TestChangeMode.py && python3.4 -m unittest intelligine/tests/simulation/pheromone/TestDirection.py
5 9
 """