def test_forked_return_const_to_non_const(self): """Constant node w/ forked return -> non-constant -> exit.""" s = StateSaver(int) with DeltaGraph() as graph: val = return_12() s.save_and_exit(increment_non_const(val.x)) DeltaPySimulator(graph).run() self.assertEqual(s.saved, [2])
def test_splitting_of_multiple_forked_const(self): """Multiple forked outputs of a constant node are splitted.""" s = StateSaver(int) with DeltaGraph() as graph: val = return_12() s.save_and_exit( add_non_const( add_non_const(add_non_const(val.x, val.x), val.y), val.y)) DeltaPySimulator(graph).run() self.assertEqual(s.saved, [6])
def test_splitting_of_one_forked_const(self): """One of forked outputs of a constant node is splitted.""" s1 = StateSaver(int) s2 = StateSaver(int) with DeltaGraph() as graph: val = return_12() val_x = val.x s1.save(val_x) s2.save_and_exit(val_x) rt = DeltaPySimulator(graph) rt.run() self.assertEqual(s2.saved, [1])
def test_forked_folding_all_const(self): """Check the case with a forked return. All the forked outputs go to const nodes -> source is a constant node as well. """ with DeltaGraph() as graph: nums = return_12() p1 = foo_const(nums.x) p2 = foo_const(nums.y) self.assertIsInstance(nums.body, PyConstBody) self.assertIsInstance(p1.body, PyConstBody) self.assertIsInstance(p2.body, PyConstBody)
def test_forked_folding_one_non_const(self): """Check the case with a forked return. One forked output goes to a non-const node -> the rest of destinations stay const. """ with DeltaGraph() as graph: nums = return_12() p1 = foo_const(nums.x) p2 = foo_non_const(nums.y) self.assertIsInstance(nums.body, PyConstBody) self.assertIsInstance(p1.body, PyConstBody) self.assertIsInstance(p2.body, PyFuncBody) self.assertTrue(graph.check())
def test_forked_folding_one_non_const_splitting(self): """Check the case with a forked return. Same as above but with splitting -> no funny business. """ with DeltaGraph() as graph: nums = return_12() p1 = foo_const(nums.x) p2 = foo_non_const(nums.y) p3 = foo_const(nums.x) p4 = foo_const(nums.y) self.assertIsInstance(nums.body, PyConstBody) self.assertIsInstance(p1.body, PyConstBody) self.assertIsInstance(p2.body, PyFuncBody) self.assertIsInstance(p3.body, PyConstBody) self.assertIsInstance(p4.body, PyConstBody)
def setUp(self): r"""Build the graph ``` / saver1 / placeholder -- saver2 \ \ saver3 ``` """ with DeltaGraph() as my_graph: saver1 = StateSaver(int) saver2 = StateSaver(int) saver3 = StateSaver(int) val = return_12() saver1.save(val=val.x) saver2.save(val=val.x) saver3.save(val=val.y) self.graph = my_graph self.savers = [saver1, saver2, saver3]