TestSimulation._test_cycles()   B
last analyzed

Complexity

Conditions 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 27
rs 8.8571
1
import unittest
2
from synergine.test.TestSimulation import TestSimulation as BaseTestSimulation
3
from synergine.test.TestTerminal import TestTerminal
4
from tests.src.TestCollection import TestCollection
5
from tests.src.TestSimulation import TestSimulation as TestSimulationSimulation
6
from tests.src.TestCollectionConfiguration import TestCollectionConfiguration
7
8
class TestSimulation(BaseTestSimulation):
9
10
    def _get_set_up_simulations(self):
11
        return [TestSimulationSimulation([TestCollection(TestCollectionConfiguration())])]
12
13
    def test_cycles_in_main_process(self):
14
        self._test_cycles(True)
15
16
    def test_cycles_in_sub_process(self):
17
        self._test_cycles(False)
18
19
    def _test_cycles(self, main_process):
20
        tests = {
21
            0: [('john', 2, 2),
22
                    ('boby', 2, 5),
23
                    ('cora', 2, 10),
24
                    ('mara', 2, 20)],
25
            1: [('john', 4, 2),
26
                    ('boby', 32, 5),
27
                    ('cora', 1024, 10),
28
                    ('mara', 1048576, 20)],
29
            2: [('john', 16, 2),
30
                    ('boby', 0, 5),
31
                    ('cora', 0, 10),
32
                    ('mara', 0, 20)],
33
            3: [('john', 256, 2),
34
                    ('boby', 0, 5),
35
                    ('cora', 0, 10),
36
                    ('mara', 0, 20)],
37
            4: [('john', 65536, 2),
38
                    ('boby', 0, 5),
39
                    ('cora', 0, 10),
40
                    ('mara', 0, 20)],
41
            5: [],
42
        }
43
        for cycle in tests:
44
            synergy_object_manager = self._get_synergy_object_manager_for_cycle(cycles=cycle, main_process=main_process)
45
            self.assertEqual(sorted(tests[cycle]), sorted(self._get_objects_resume(synergy_object_manager)))
46
47
    def _get_objects_resume(self, synergy_object_manager):
48
        resume = []
49
        for obj in synergy_object_manager.get_objects():
50
            resume.append((obj.name, obj.beans, obj.coeff))
51
        return resume