def test_prim_typeof(): assert typeof(1) == i64 assert typeof(1.2) == f64 assert typeof((1, 2.0, (3, 4))) == Tuple[i64, f64, Tuple[i64, i64]] assert typeof([1, 2]) == List[i64] with pytest.raises(TypeError): typeof([1, 2, 3.4]) assert typeof(object()) == External[object] assert typeof(i64) == TypeType assert typeof(int) == TypeType
def test_switch_nontail(): def fn(x, y): def f1(): return x def f2(): return y a = P.switch(x > y, f1, f2)() return a * a i64 = typeof(1) argspec = (to_abstract_test(i64), to_abstract_test(i64)) myia_fn = compile_pipeline.run(input=fn, argspec=argspec)['output'] for test in [(6, 23, 23**2), (67, 23, 67**2)]: *args, expected = test assert myia_fn(*args) == expected
def test_typeof(x): return typeof(x)
def Poss(*things): return _S({ VALUE: _Poss(things), TYPE: typeof(things[0]), })
def S(v=ANYTHING, t=None, s=None): return _S({ VALUE: v, TYPE: t or typeof(v), })