Example #1
0
 def test_nested_empty(self):
     states = [
         composite('a', [
             orthogonal('submachines', [
                 composite('sub1', [
                     leaf('sub11'),
                     composite('sub12', [
                         leaf('sub121'),
                         leaf('sub122'),
                     ])
                 ]),
                 composite('sub2', [
                     leaf('sub21'),
                     composite('sub22', [
                         leaf('sub221'),
                         leaf('sub222'),
                     ]),
                 ]),
             ]),
             composite('b', [
                 leaf('b1')
             ]),
         ]),
         composite('c', [
             leaf('c1'),
             leaf('c2'),
         ]),
     ]
     names = [st.name for st in flatten(states)]
     expected = ['a', 'submachines', 'sub1', 'sub11', 'sub12', 'sub121',
                 'sub122', 'sub2', 'sub21', 'sub22', 'sub221', 'sub222',
                 'b', 'b1', 'c', 'c1', 'c2']
     assert len(names) == len(expected)
     assert set(names) == set(expected)
Example #2
0
 def test_with_list(self):
     a = [1, 2, [3, 4, [5, 6], 7, [8, 9]], 10, [11, [12, 13]], 14]
     exp = list(range(1, 15))
     assert sorted(flatten(a)) == sorted(exp)
Example #3
0
 def test_single_empty(self):
     assert flatten([]) == []