def test_basic_operator(self): self.check(BinaryOperator('+', IntegerLiteral(10), IntegerLiteral(20)), 30) self.check(BinaryOperator('-', IntegerLiteral(50), IntegerLiteral(2)), 48) self.check(BinaryOperator('*', IntegerLiteral(10), IntegerLiteral(5)), 50) self.check(BinaryOperator('/', IntegerLiteral(50), IntegerLiteral(10)), 5)
def test_priorities(self): self.check( BinaryOperator( '+', IntegerLiteral(1), BinaryOperator('*', IntegerLiteral(2), IntegerLiteral(3))), 7) self.check( BinaryOperator( '-', BinaryOperator('*', IntegerLiteral(5), IntegerLiteral(4)), IntegerLiteral(20)), 0) self.check( BinaryOperator( '-', BinaryOperator('/', IntegerLiteral(6), IntegerLiteral(2)), IntegerLiteral(1)), 2)
def test_basic_operator_arith(self): self.check(BinaryOperator('-', IntegerLiteral(10), IntegerLiteral(5)), 5) self.parse_check('10 - 1 - 2', 7) self.check(BinaryOperator('/', IntegerLiteral(6), IntegerLiteral(2)), 3) self.check(BinaryOperator('*', IntegerLiteral(6), IntegerLiteral(2)), 12) self.check(BinaryOperator('/', IntegerLiteral(5), IntegerLiteral(2)), 2)
def test_literal(self): self.check(IntegerLiteral(42), 42)
def test_basic_comparison(self): self.check(BinaryOperator('<', IntegerLiteral(5), IntegerLiteral(3)), 0) self.check(BinaryOperator('<', IntegerLiteral(1), IntegerLiteral(4)), 1) self.check(BinaryOperator('<', IntegerLiteral(5), IntegerLiteral(5)), 0) self.check(BinaryOperator('<=', IntegerLiteral(5), IntegerLiteral(3)), 0) self.check(BinaryOperator('<=', IntegerLiteral(1), IntegerLiteral(4)), 1) self.check(BinaryOperator('<=', IntegerLiteral(5), IntegerLiteral(5)), 1) self.check(BinaryOperator('>', IntegerLiteral(5), IntegerLiteral(3)), 1) self.check(BinaryOperator('>', IntegerLiteral(1), IntegerLiteral(4)), 0) self.check(BinaryOperator('>', IntegerLiteral(5), IntegerLiteral(5)), 0) self.check(BinaryOperator('>=', IntegerLiteral(5), IntegerLiteral(3)), 1) self.check(BinaryOperator('>=', IntegerLiteral(1), IntegerLiteral(4)), 0) self.check(BinaryOperator('>=', IntegerLiteral(5), IntegerLiteral(5)), 1) self.check(BinaryOperator('=', IntegerLiteral(3), IntegerLiteral(5)), 0) self.check(BinaryOperator('=', IntegerLiteral(5), IntegerLiteral(5)), 1) self.check(BinaryOperator('<>', IntegerLiteral(3), IntegerLiteral(5)), 1) self.check(BinaryOperator('<>', IntegerLiteral(5), IntegerLiteral(5)), 0)
def test_basic_operator_logic(self): self.check(BinaryOperator('|', IntegerLiteral(1), IntegerLiteral(0)), 1) self.check(BinaryOperator('|', IntegerLiteral(0), IntegerLiteral(0)), 0) self.check(BinaryOperator('|', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('|', IntegerLiteral(4), IntegerLiteral(2)), 1) self.check(BinaryOperator('&', IntegerLiteral(1), IntegerLiteral(0)), 0) self.check(BinaryOperator('&', IntegerLiteral(0), IntegerLiteral(0)), 0) self.check(BinaryOperator('&', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('&', IntegerLiteral(4), IntegerLiteral(2)), 1) self.parse_check('0 & 2 / 0', 0)
def test_priorities(self): self.check( BinaryOperator( '+', IntegerLiteral(1), BinaryOperator('*', IntegerLiteral(2), IntegerLiteral(3))), 7)
def test_basic_operator(self): self.check(BinaryOperator('+', IntegerLiteral(10), IntegerLiteral(20)), 30)
def test_ifThenElse(self): self.check(IfThenElse(IntegerLiteral(1), IntegerLiteral(2), IntegerLiteral(3)), 2) self.check(IfThenElse(IntegerLiteral(0), IntegerLiteral(2), IntegerLiteral(3)), 3)
def test_binop(self): self.check(BinaryOperator('*', IntegerLiteral(6), IntegerLiteral(7)), 42) self.check(BinaryOperator('-', IntegerLiteral(10), IntegerLiteral(1)), 9) self.check(BinaryOperator('/', IntegerLiteral(42), IntegerLiteral(7)), 6) self.check(BinaryOperator('/', IntegerLiteral(42), IntegerLiteral(5)), 8) self.check(BinaryOperator('&', IntegerLiteral(0), IntegerLiteral(0)), 0) self.check(BinaryOperator('&', IntegerLiteral(0), IntegerLiteral(1)), 0) self.check(BinaryOperator('&', IntegerLiteral(1), IntegerLiteral(0)), 0) self.check(BinaryOperator('&', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('|', IntegerLiteral(0), IntegerLiteral(0)), 0) self.check(BinaryOperator('|', IntegerLiteral(0), IntegerLiteral(1)), 1) self.check(BinaryOperator('|', IntegerLiteral(1), IntegerLiteral(0)), 1) self.check(BinaryOperator('|', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('<', IntegerLiteral(0), IntegerLiteral(1)), 1) self.check(BinaryOperator('<', IntegerLiteral(1), IntegerLiteral(1)), 0) self.check(BinaryOperator('<', IntegerLiteral(1), IntegerLiteral(0)), 0) self.check(BinaryOperator('<=', IntegerLiteral(0), IntegerLiteral(1)), 1) self.check(BinaryOperator('<=', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('<=', IntegerLiteral(1), IntegerLiteral(0)), 0) self.check(BinaryOperator('>', IntegerLiteral(0), IntegerLiteral(1)), 0) self.check(BinaryOperator('>', IntegerLiteral(1), IntegerLiteral(1)), 0) self.check(BinaryOperator('>', IntegerLiteral(1), IntegerLiteral(0)), 1) self.check(BinaryOperator('>=', IntegerLiteral(0), IntegerLiteral(1)), 0) self.check(BinaryOperator('>=', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('>=', IntegerLiteral(1), IntegerLiteral(0)), 1) self.check(BinaryOperator('=', IntegerLiteral(0), IntegerLiteral(1)), 0) self.check(BinaryOperator('=', IntegerLiteral(1), IntegerLiteral(1)), 1) self.check(BinaryOperator('<>', IntegerLiteral(0), IntegerLiteral(1)), 1) self.check(BinaryOperator('<>', IntegerLiteral(1), IntegerLiteral(1)), 0)