def test_nx(): g = nx.DiGraph() g.inputs = {'a': '...', 'b': '...'} g.outputs = {'c': '...', 'd': '...'} start = 'Sinit' g.add_edge(start, 0, a=0, b=0, c=0, d=0) g.add_edge(0, 1, a=0, b=1, c=0, d=1) g.add_edge(1, 2, a=1, b=0, c=1, d=1) print(dumpsmach.python_case(g, classname='Machine', start='Sinit')) exec dumpsmach.python_case(g, classname='Machine', start='Sinit') m = Machine() # previous line creates the class `Machine` # Sinit -> 0 out = m.move(a=0, b=0) assert out == dict(c=0, d=0) # 0 -> 1 out = m.move(a=0, b=1) assert out == dict(c=0, d=1) # invalid input for index 2 in time sequence with assert_raises(ValueError): m.move(a=1, b=1) # 1 -> 2 out = m.move(a=1, b=0) assert out == dict(c=1, d=1) # dead-end with assert_raises(Exception): m.move(a=1, b=0)
def test_nx(): g = nx.DiGraph() g.inputs = {'a': '...', 'b': '...'} g.outputs = {'c': '...', 'd': '...'} start = 'Sinit' g.add_edge(start, 0, a=0, b=0, c=0, d=0) g.add_edge(0, 1, a=0, b=1, c=0, d=1) g.add_edge(1, 2, a=1, b=0, c=1, d=1) print(dumpsmach.python_case(g, classname='Machine', start='Sinit')) exe_globals = dict() exec(dumpsmach.python_case(g, classname='Machine', start='Sinit'), exe_globals) m = exe_globals['Machine']() # previous line creates the class `Machine` # Sinit -> 0 out = m.move(a=0, b=0) assert out == dict(c=0, d=0) # 0 -> 1 out = m.move(a=0, b=1) assert out == dict(c=0, d=1) # invalid input for index 2 in time sequence with assert_raises(ValueError): m.move(a=1, b=1) # 1 -> 2 out = m.move(a=1, b=0) assert out == dict(c=1, d=1) # dead-end with assert_raises(Exception): m.move(a=1, b=0)
def test_python_case(self): compile(dumpsmach.python_case(self.triv_M), filename="<string>", mode="exec") # print(dumpsmach.python_case(self.dcounter_M)) compile(dumpsmach.python_case(self.dcounter_M), filename="<string>", mode="exec") exec compile(dumpsmach.python_case(self.enumf_M) +'\nM = TulipStrategy(); M.move()', filename="<string>", mode="exec")
def test_python_case(self): compile(dumpsmach.python_case(self.triv_M), filename="<string>", mode="exec") # print(dumpsmach.python_case(self.dcounter_M)) compile(dumpsmach.python_case(self.dcounter_M), filename="<string>", mode="exec") exec(compile(dumpsmach.python_case(self.enumf_M) +'\nM = TulipStrategy(); M.move()', filename="<string>", mode="exec"))