def test_universe_commit(): U = new_universe h1 = HandleInstance(2) h2 = HandleInstance(7) U = U.set(h1, 20) U = U.set(h2, 70) assert h1.state == 2 assert h2.state == 7 U.commit() assert h1.state == 20 assert h2.state == 70
def convert_handle(self, v, t): return HandleInstance(self(v.value, t.element))
infer(UniverseType, i64, i64, result=InferenceError), ) def test_universe_setitem(U, h, v): return universe_setitem(U, h, v) def _test_universe_chk(args, U): U0, h, x, y = args assert U.get(h) == h.state * (x + y) return True @mt( infer(UniverseType, H(i64), i64, i64, result=UniverseType), infer(UniverseType, H(i64), f64, f64, result=InferenceError), run_debug(new_universe, HandleInstance(2), 3, 4, result=_test_universe_chk), ) def test_universe(U, h, x, y): init = universe_getitem(U, h) U = universe_setitem(U, h, x + y) xy = universe_getitem(U, h) return universe_setitem(U, h, init * xy) def test_universe_commit(): U = new_universe h1 = HandleInstance(2) h2 = HandleInstance(7) U = U.set(h1, 20) U = U.set(h2, 70)
def test_to_canonical(): def _convert(data, typ): return to_canonical(data, to_abstract_test(typ)) # Leaves assert _convert(True, Bool) is True assert _convert(False, Bool) is False assert _convert(10, i64) == 10 assert _convert(1.5, f64) == 1.5 assert _convert([], []) == () with pytest.raises(TypeError): _convert([], [f64]) with pytest.raises(TypeError): _convert([1, 2], []) # Class -> Tuple conversion pt = Point(1, 2) pt3 = Point3D(1, 2, 3) assert list(_convert(pt, Point(i64, i64))) == [1, 2] with pytest.raises(TypeError): _convert((1, 2), Point(i64, i64)) assert list(_convert( (pt, pt), (Point(i64, i64), Point(i64, i64)))) == [(1, 2), (1, 2)] li = _convert([1], [i64]) assert (isinstance(li, tuple) and li[0] == 1 and isinstance(li[1], TaggedValue) and li[1].value == ()) # Arrays fmat = np.ones((5, 8)) imat = np.ones((5, 8), dtype='int32') assert _convert(fmat, af64_of(5, 8)) is fmat assert _convert(imat, ai32_of(5, 8)) is imat with pytest.raises(TypeError): _convert(imat, ai64_of(5, 8)) with pytest.raises(TypeError): _convert(imat, ai32_of(4, 8)) # Misc errors with pytest.raises(TypeError): _convert(10, f64) with pytest.raises(TypeError): _convert(1.5, i64) with pytest.raises(TypeError): _convert(10, (i64, i64)) with pytest.raises(TypeError): _convert((1, ), (i64, i64)) with pytest.raises(TypeError): _convert((1, 2, 3), (i64, i64)) with pytest.raises(TypeError): _convert((1, 2, 3), [i64]) with pytest.raises(TypeError): _convert(pt3, Point(i64, i64)) with pytest.raises(TypeError): _convert(10, ai64_of()) with pytest.raises(TypeError): _convert(10, ai64_of()) with pytest.raises(TypeError): _convert(1, Bool) with pytest.raises(TypeError): _convert(1, D(x=i64)) with pytest.raises(TypeError): _convert({'x': 2.0}, D(x=i64)) with pytest.raises(TypeError): _convert({'x': 2.0, 'y': 1}, D(x=i64)) with pytest.raises(TypeError): _convert({'y': 2.0}, D(x=i64)) with pytest.raises(TypeError): _convert('x', 1.0) with pytest.raises(TypeError): _convert(1.0, to_abstract_test('x')) with pytest.raises(TypeError): _convert(1.0, to_abstract_test(HandleInstance(1.0))) v = to_device(22, None) with pytest.raises(TypeError): _convert(v, f64)