def test_duallinker_straightforward(): x, y, z = inputs() e = add(mul(x, y), mul(y, z)) # add and mul are correct in C and in Python lnk = DualLinker(checker=_my_checker).accept(FunctionGraph([x, y, z], [e])) fn = lnk.make_function() res = fn(7.2, 1.5, 3.0) assert res == 15.3
def test_duallinker_mismatch(): x, y, z = inputs() # bad_sub is correct in C but erroneous in Python e = bad_sub(mul(x, y), mul(y, z)) g = FunctionGraph([x, y, z], [e]) lnk = DualLinker(checker=_my_checker).accept(g) fn = lnk.make_function() # good assert CLinker().accept(g).make_function()(1.0, 2.0, 3.0) == -4.0 # good assert OpWiseCLinker().accept(g).make_function()(1.0, 2.0, 3.0) == -4.0 # (purposely) wrong assert PerformLinker().accept(g).make_function()(1.0, 2.0, 3.0) == -10.0 with pytest.raises(MyExc): # this runs OpWiseCLinker and PerformLinker in parallel and feeds # variables of matching operations to _my_checker to verify that they # are the same. fn(1.0, 2.0, 3.0)