def test_vector_constructor(): ctx = Qit() s = Struct(Int(), Int()) v = Vector(s) x = Variable(s, "x") result = ctx.run(v.value([x, s.value((7, 2)), (1, 2)]), args={x: (11,12)}) assert result == [ (11, 12), (7, 2), (1, 2) ]
def test_class_method(): ctx = Qit() p = Struct((Int(), "x"), (Int(), "y")) m1 = p.method("get").returns(Int()).code("return self.x + self.y;") cls = Class(p, (m1,)) f = Function().returns(Int()).takes(cls, "a").code("return a.get();") result = ctx.run(f(cls.value((20, 31)))) assert result == 51
def test_class_method_free_var(): ctx = Qit() p = Struct((Int(), "x"), (Int(), "qit_freevar_y")) y = Variable(Int(), "y") m1 = p.method("get").returns(Int()).reads(y).takes(Int(), "a") m1.code("return a + {{y}};", y=y) cls = Class(p, (m1,)) f = Function().returns(Int()).takes(cls, "a").code("return a.get(5);") result = ctx.run(f(cls.value((20, 31)))) assert result == 36
return {new_marking}; } return {}; """, is_enabled=fs_enabled[t], t_marking=t_marking, tid=Int().value(t)) for t in range(N_EVENTS)) statespace = ActionSystem(Values(t_marking, [v_marking]), fs_fire) states = statespace.states(DEPTH) f_states = states.iterate().make_function((v_marking, v_input_arcs, v_output_arcs)) init_values = Product((M0, "init_marking"), (Wi, "input"), (Wo, "output")) t_element = statespace.sas_type t_states = Vector(t_element) t_input = init_values.as_type() t_result = Struct((init_values, "init_values"), (t_states, "lts")) f_process_input = Function("map_variables").takes(init_values, "init_values").returns(t_result) f_process_input.code(""" return {{t_result}}(init_values, {{f_states}}(init_values.init_marking, init_values.input, init_values.output)); """, f_states=f_states, t_result=t_result,) f_eq_states = Function("eq_states").takes(t_element, "s1").takes(t_element, "s2").returns(Bool()) f_eq_states.code(""" return s1.s1_id == s2.s1_id && s1.action == s2.action && s1.s2_id == s2.s2_id; """) input_lts = t_states.value([t_element.value((1, "t0", 2)), t_element.value((2, "t0", 3)), t_element.value((3, "t1", 4)),
def test_struct_empty(): ctx = Qit() s1 = Struct() ctx.run(s1.value(()))