def test_array_literal(self): code = "a = [1,2,3]" interp = self.compile(code) assert isinstance(interp.code.statements[0].expr, ArrayConstant) st = interp.code.statements[0] assert st.expr.items == [FloatConstant(1), FloatConstant(2), FloatConstant(3)]
def test_array_literal2(self): code = "a = [[1],[2],[3]]" interp = self.compile(code) assert isinstance(interp.code.statements[0].expr, ArrayConstant) st = interp.code.statements[0] assert st.expr.items == [ArrayConstant([FloatConstant(1)]), ArrayConstant([FloatConstant(2)]), ArrayConstant([FloatConstant(3)])]
def test_comment(self): code = """ # some comment a = b + 3 # another comment """ interp = self.compile(code) assert interp.code.statements[0] == Assignment( 'a', Operator(Variable('b'), "+", FloatConstant(3)))
def test_array_access(self): code = "a -> 3" interp = self.compile(code) assert interp.code.statements[0] == Execute( Operator(Variable("a"), "->", FloatConstant(3)))
def test_expr_only(self): code = "3 + a" interp = self.compile(code) assert interp.code.statements[0] == Execute( Operator(FloatConstant(3), "+", Variable("a")))
def test_expr_2(self): code = "b = a + b - 3" interp = self.compile(code) assert (interp.code.statements[0].expr == Operator(Operator(Variable("a"), "+", Variable("b")), "-", FloatConstant(3)))
def test_expr_1(self): code = "b = a + 1" interp = self.compile(code) assert (interp.code.statements[0].expr == Operator(Variable("a"), "+", FloatConstant(1)))