|
@@ -1,6 +1,7 @@
|
1
|
1
|
# coding: utf-8
|
2
|
2
|
# -*- coding: utf-8 -*-
|
3
|
3
|
from synergine2.config import Config
|
|
4
|
+from synergine2.share import shared
|
4
|
5
|
from synergine2.simulation import Subject
|
5
|
6
|
from synergine2_xyz.mechanism import ProximitySubjectMechanism
|
6
|
7
|
from synergine2_xyz.simulation import XYZSimulation
|
|
@@ -22,7 +23,13 @@ class MyProximityMechanism(ProximitySubjectMechanism):
|
22
|
23
|
|
23
|
24
|
class TestXYZ(BaseTest):
|
24
|
25
|
def test_proximity_mechanism_with_one(self):
|
|
26
|
+ shared.reset()
|
25
|
27
|
simulation = XYZSimulation(Config())
|
|
28
|
+ simulation.add_to_index(
|
|
29
|
+ MyProximityMechanism,
|
|
30
|
+ MySubject,
|
|
31
|
+ )
|
|
32
|
+
|
26
|
33
|
subject = MySubject(Config(), simulation, position=(0, 0, 0))
|
27
|
34
|
other_subject = MySubject(Config(), simulation, position=(5, 0, 0))
|
28
|
35
|
|
|
@@ -30,6 +37,7 @@ class TestXYZ(BaseTest):
|
30
|
37
|
[subject, other_subject],
|
31
|
38
|
simulation=simulation,
|
32
|
39
|
)
|
|
40
|
+ simulation.subjects.auto_expose = False
|
33
|
41
|
|
34
|
42
|
proximity_mechanism = MyProximityMechanism(
|
35
|
43
|
config=Config(),
|
|
@@ -42,13 +50,19 @@ class TestXYZ(BaseTest):
|
42
|
50
|
subject=other_subject,
|
43
|
51
|
)
|
44
|
52
|
assert [{
|
45
|
|
- 'subject': other_subject,
|
|
53
|
+ 'subject_id': other_subject.id,
|
46
|
54
|
'direction': 90.0,
|
47
|
55
|
'distance': 5.0,
|
48
|
56
|
}] == proximity_mechanism.run()
|
49
|
57
|
|
50
|
58
|
def test_proximity_mechanism_excluding(self):
|
|
59
|
+ shared.reset()
|
51
|
60
|
simulation = XYZSimulation(Config())
|
|
61
|
+ simulation.add_to_index(
|
|
62
|
+ MyProximityMechanism,
|
|
63
|
+ MySubject,
|
|
64
|
+ )
|
|
65
|
+
|
52
|
66
|
subject = MySubject(Config(), simulation, position=(0, 0, 0))
|
53
|
67
|
other_subject = MySubject(Config(), simulation, position=(11, 0, 0))
|
54
|
68
|
|
|
@@ -56,6 +70,7 @@ class TestXYZ(BaseTest):
|
56
|
70
|
[subject, other_subject],
|
57
|
71
|
simulation=simulation,
|
58
|
72
|
)
|
|
73
|
+ simulation.subjects.auto_expose = False
|
59
|
74
|
|
60
|
75
|
proximity_mechanism = MyProximityMechanism(
|
61
|
76
|
config=Config(),
|
|
@@ -71,7 +86,13 @@ class TestXYZ(BaseTest):
|
71
|
86
|
assert [] == proximity_mechanism.run()
|
72
|
87
|
|
73
|
88
|
def test_proximity_mechanism_with_multiple(self):
|
|
89
|
+ shared.reset()
|
74
|
90
|
simulation = XYZSimulation(Config())
|
|
91
|
+ simulation.add_to_index(
|
|
92
|
+ MyProximityMechanism,
|
|
93
|
+ MySubject,
|
|
94
|
+ )
|
|
95
|
+
|
75
|
96
|
subject = MySubject(Config(), simulation, position=(0, 0, 0))
|
76
|
97
|
other_subjects = []
|
77
|
98
|
|
|
@@ -80,6 +101,7 @@ class TestXYZ(BaseTest):
|
80
|
101
|
|
81
|
102
|
simulation.subjects = XYZSubjects([subject], simulation=simulation)
|
82
|
103
|
simulation.subjects.extend(other_subjects)
|
|
104
|
+ simulation.subjects.auto_expose = False
|
83
|
105
|
|
84
|
106
|
proximity_mechanism = MyProximityMechanism(
|
85
|
107
|
config=Config(),
|
|
@@ -91,17 +113,17 @@ class TestXYZ(BaseTest):
|
91
|
113
|
assert [
|
92
|
114
|
{
|
93
|
115
|
'direction': 0,
|
94
|
|
- 'subject': other_subjects[0],
|
|
116
|
+ 'subject_id': other_subjects[0].id,
|
95
|
117
|
'distance': 0.0,
|
96
|
118
|
},
|
97
|
119
|
{
|
98
|
120
|
'direction': 135.0,
|
99
|
|
- 'subject': other_subjects[1],
|
|
121
|
+ 'subject_id': other_subjects[1].id,
|
100
|
122
|
'distance': 1.41
|
101
|
123
|
},
|
102
|
124
|
{
|
103
|
125
|
'direction': 135.0,
|
104
|
|
- 'subject': other_subjects[2],
|
|
126
|
+ 'subject_id': other_subjects[2].id,
|
105
|
127
|
'distance': 2.83
|
106
|
128
|
},
|
107
|
129
|
] == data
|