Beispiel #1
0
    def test_after_reformat(self):
        states = {
            'root': State({
                'left': State({
                    'left_A': State(),
                    'left_B': State(),
                }),
                'middle': State({
                    'middle_A': State(),
                    'middle_B': State(),
                    'middle_C': State(),
                }),
                'right': State({
                    'right_A': State({
                        'right_A_1':  State(),
                        'right_A_2': State(),
                    }),
                    'right_B': State(),
                })
            })
        }

        flattened = HSM(states, {}, skip_validation=True).flattened

        left_A = get_state_by_sig(('left_A',), flattened)
        left_B = get_state_by_sig(('left_B',), flattened)
        right_A_1 = get_state_by_sig(('right_A_1',), flattened)
        right_B = get_state_by_sig(('right_B',), flattened)

        assert get_common_parent(left_A, left_B).name == 'left'
        assert get_common_parent(left_A, right_A_1).name == 'root'
        assert get_common_parent(right_A_1, right_B).name == 'right'
Beispiel #2
0
 def test_multiple_nested(self):
     root = MockState(parent=None)
     ch_1 = MockState(parent=root)
     ch_2 = MockState(parent=ch_1)
     ch_3 = MockState(parent=ch_2)
     ch_4 = MockState(parent=ch_3)
     assert get_common_parent(root, ch_2) == root
     assert get_common_parent(ch_2, root) == root
     assert get_common_parent(ch_1, ch_2) == ch_1
     assert get_common_parent(ch_2, ch_1) == ch_1
     assert get_common_parent(ch_1, ch_3) == ch_1
     assert get_common_parent(ch_3, ch_1) == ch_1
     assert get_common_parent(ch_4, ch_3) == ch_3
     assert get_common_parent(ch_3, ch_4) == ch_3
     assert get_common_parent(ch_1, ch_4) == ch_1
     assert get_common_parent(root, ch_4) == root
Beispiel #3
0
    def test_branching(self):
        root = MockState(parent=None)

        left = MockState(parent=root)
        left_A = MockState(parent=left)
        left_B = MockState(parent=left)

        middle = MockState(parent=root)
        middle_A = MockState(parent=middle)

        right = MockState(parent=root)
        right_A = MockState(parent=right)
        right_A_1 = MockState(parent=right_A)
        right_A_2 = MockState(parent=right_A)

        right_B = MockState(parent=right)
        right_B_1 = MockState(parent=right_B)

        assert get_common_parent(left, middle) == root
        assert get_common_parent(middle, left) == root
        assert get_common_parent(left, right) == root
        assert get_common_parent(middle, right) == root
        assert get_common_parent(middle, root) == root
        assert get_common_parent(left_A, root) == root
        assert get_common_parent(root, left_A) == root
        assert get_common_parent(left_A, left) == left
        assert get_common_parent(left_A, left_B) == left
        assert get_common_parent(left_A, middle) == root
        assert get_common_parent(right_A, right_B) == right
        assert get_common_parent(right_A, left_A) == root
        assert get_common_parent(right_A_1, middle_A) == root
        assert get_common_parent(right_A_1, right_B) == right
        assert get_common_parent(right_A_1, right_A_2) == right_A
        assert get_common_parent(right_A_1, right_B_1) == right
Beispiel #4
0
 def test_one_nested(self):
     root = MockState(parent=None)
     ch_1 = MockState(parent=root)
     assert get_common_parent(root, ch_1) == root
     assert get_common_parent(ch_1, root) == root
     assert get_common_parent(ch_1, ch_1) == ch_1
Beispiel #5
0
 def test_single_node(self):
     root = MockState(parent=None)
     assert get_common_parent(root, root) == root