Ejemplo n.º 1
0
    def test_equal_two_numbers(self):
        expr = TypeOperations.equals(self.number1, self.number2)

        self.assertFalse(expr.value)
        self.assertEqual("3 := 5", expr.name)

        expr2 = TypeOperations.equals(self.number1, self.number1)
        self.assertTrue(expr2.value)
Ejemplo n.º 2
0
    def test_plus_number_boolean(self):
        expr = TypeOperations.plus(self.number1, self.boolean_true)
        self.assertEqual(4, expr.value)
        self.assertEqual("3 + True", expr.name)

        expr2 = TypeOperations.plus(self.boolean_false, self.number1)
        self.assertEqual(3, expr2.value)
        self.assertEqual("False + 3", expr2.name)
Ejemplo n.º 3
0
    def test_equals_string_boolean(self):
        expr = TypeOperations.equals(self.string1, self.boolean_true)
        self.assertFalse(expr.value)
        self.assertEqual("firstString := True", expr.name)

        expr2 = TypeOperations.equals(self.boolean_false, self.string1)
        self.assertFalse(expr2.value)
        self.assertEqual("False := firstString", expr2.name)
Ejemplo n.º 4
0
    def test_minus_two_booleans(self):
        expr = TypeOperations.minus(self.boolean_true, self.boolean_true)
        self.assertEqual(0, expr.value)
        self.assertEqual("True - True", expr.name)

        expr2 = TypeOperations.minus(self.boolean_false, self.boolean_true)
        self.assertEqual(-1, expr2.value)
        self.assertEqual("False - True", expr2.name)
Ejemplo n.º 5
0
    def test_equals_two_string(self):
        expr = TypeOperations.equals(self.string1, self.string1)
        self.assertTrue(expr.value)
        self.assertEqual("firstString := firstString", expr.name)

        expr2 = TypeOperations.equals(self.string2, self.string1)
        self.assertFalse(expr2.value)
        self.assertEqual("secondString := firstString", expr2.name)
Ejemplo n.º 6
0
    def test_plus_number_string(self):
        expr = TypeOperations.plus(self.number1, self.string1)
        self.assertEqual("3firstString", expr.value)
        self.assertEqual("3 + firstString", expr.name)

        expr = TypeOperations.plus(self.string1, self.number1)
        self.assertEqual("firstString3", expr.value)
        self.assertEqual("firstString + 3", expr.name)
Ejemplo n.º 7
0
    def test_minus_number_boolean(self):
        expr = TypeOperations.minus(self.number1, self.boolean_true)
        self.assertEqual(2, expr.value)
        self.assertEqual("3 - True", expr.name)

        expr2 = TypeOperations.minus(self.boolean_false, self.number1)
        self.assertEqual(-3, expr2.value)
        self.assertEqual("False - 3", expr2.name)
Ejemplo n.º 8
0
    def test_div_number_boolean(self):
        expr = TypeOperations.div(self.number1, self.boolean_true)
        self.assertEqual(3, expr.value)
        self.assertEqual("3 / True", expr.name)

        expr2 = TypeOperations.div(self.boolean_false, self.number1)
        self.assertEqual(0, expr2.value)
        self.assertEqual("False / 3", expr2.name)
Ejemplo n.º 9
0
    def test_div_two_booleans(self):
        expr = TypeOperations.div(self.boolean_true, self.boolean_true)
        self.assertEqual(1, expr.value)
        self.assertEqual("True / True", expr.name)

        expr2 = TypeOperations.div(self.boolean_false, self.boolean_true)
        self.assertEqual(0, expr2.value)
        self.assertEqual("False / True", expr2.name)
Ejemplo n.º 10
0
    def test_plus_boolean_string(self):
        expr = TypeOperations.plus(self.string1, self.boolean_false)
        self.assertEqual("firstStringFalse", expr.value)
        self.assertEqual("firstString + False", expr.name)

        expr2 = TypeOperations.plus(self.boolean_true, self.string1)
        self.assertEqual("TruefirstString", expr2.value)
        self.assertEqual("True + firstString", expr2.name)
Ejemplo n.º 11
0
    def test_plus_two_string(self):
        expr = TypeOperations.plus(self.string1, self.string2)
        self.assertEqual("firstStringsecondString", expr.value)
        self.assertEqual("firstString + secondString", expr.name)

        expr2 = TypeOperations.plus(self.string2, self.string1)
        self.assertEqual("secondStringfirstString", expr2.value)
        self.assertEqual("secondString + firstString", expr2.name)
Ejemplo n.º 12
0
    def test_mult_number_boolean(self):
        expr = TypeOperations.mult(self.number1, self.boolean_true)
        self.assertEqual(3, expr.value)
        self.assertEqual("3 * True", expr.name)

        expr2 = TypeOperations.mult(self.boolean_false, self.number1)
        self.assertEqual(0, expr2.value)
        self.assertEqual("False * 3", expr2.name)
Ejemplo n.º 13
0
    def test_equal_two_booleans(self):
        expr = TypeOperations.equals(self.boolean_true, self.boolean_true)
        self.assertTrue(expr.value)
        self.assertEqual("True := True", expr.name)

        expr2 = TypeOperations.equals(self.boolean_false, self.boolean_true)
        self.assertFalse(expr2.value)
        self.assertEqual("False := True", expr2.name)
Ejemplo n.º 14
0
    def test_mult_two_booleans(self):
        expr = TypeOperations.mult(self.boolean_true, self.boolean_true)
        self.assertEqual(1, expr.value)
        self.assertEqual("True * True", expr.name)

        expr2 = TypeOperations.mult(self.boolean_true, self.boolean_false)
        self.assertEqual(0, expr2.value)
        self.assertEqual("True * False", expr2.name)
Ejemplo n.º 15
0
    def test_equal_number_boolean(self):
        expr = TypeOperations.equals(self.number1, self.boolean_true)
        self.assertFalse(expr.value)
        self.assertEqual("3 := True", expr.name)

        zero = BasicExpression(ConfprolObject(0), 0, ValueType.NUMBER)
        expr2 = TypeOperations.equals(self.boolean_false, zero)
        self.assertTrue(expr2.value)
        self.assertEqual("False := 0", expr2.name)
Ejemplo n.º 16
0
    def test_equal_number_string(self):
        three_str = BasicExpression(ConfprolObject("3"), "3", ValueType.STRING)
        expr = TypeOperations.equals(self.number1, three_str)
        self.assertFalse(expr.value)
        self.assertEqual("3 := 3", expr.name)

        expr2 = TypeOperations.equals(self.string1, self.number2)
        self.assertFalse(expr2.value)
        self.assertEqual("firstString := 5", expr2.name)
Ejemplo n.º 17
0
 def division(self, expr1: BasicExpression, expr2: BasicExpression, line):
     try:
         return TypeOperations.div(expr1, expr2)
     except (DivisionByZero, ConfprolException) as e:
         raise RuntimeException(line, e)
Ejemplo n.º 18
0
 def minus(self, expr1: BasicExpression, expr2: BasicExpression, line):
     try:
         return TypeOperations.minus(expr1, expr2)
     except ConfprolException as e:
         raise RuntimeException(line, e)
Ejemplo n.º 19
0
    def test_mult_number_string(self):
        with self.assertRaises(OperationNotSupported):
            TypeOperations.mult(self.number1, self.string1)

        with self.assertRaises(OperationNotSupported):
            TypeOperations.mult(self.string2, self.number1)
Ejemplo n.º 20
0
 def test_plus_first_argument_not_expression(self):
     with self.assertRaises(AttributeError):
         TypeOperations.plus(self.string2, 3)
Ejemplo n.º 21
0
    def test_mult_two_numbers(self):
        expr = TypeOperations.mult(self.number1, self.number2)

        self.assertEqual(15, expr.value)
        self.assertEqual("3 * 5", expr.name)
Ejemplo n.º 22
0
 def test_div_by_0(self):
     zero = BasicExpression(ConfprolObject(0), 0, ValueType.NUMBER)
     with self.assertRaises(DivisionByZero):
         TypeOperations.div(self.number1, zero)
Ejemplo n.º 23
0
    def test_div_two_numbers(self):
        expr = TypeOperations.div(self.number1, self.number2)

        self.assertEqual(3 / 5, expr.value, 0.00000001)
        self.assertEqual("3 / 5", expr.name)
Ejemplo n.º 24
0
    def test_minus_two_numbers(self):
        expr = TypeOperations.minus(self.number1, self.number2)

        self.assertEqual(-2, expr.value)
        self.assertEqual("3 - 5", expr.name)
Ejemplo n.º 25
0
 def test_plus_two_booleans(self):
     expr = TypeOperations.plus(self.boolean_true, self.boolean_false)
     self.assertEqual(1, expr.value)
     self.assertEqual("True + False", expr.name)
Ejemplo n.º 26
0
 def test_equals_second_argument_not_expression(self):
     with self.assertRaises(AttributeError):
         TypeOperations.div(3, self.string2)
Ejemplo n.º 27
0
    def test_minus_string_boolean(self):
        with self.assertRaises(OperationNotSupported):
            TypeOperations.div(self.boolean_true, self.string1)

        with self.assertRaises(OperationNotSupported):
            TypeOperations.div(self.string2, self.boolean_false)
Ejemplo n.º 28
0
 def test_minus_two_string(self):
     with self.assertRaises(OperationNotSupported):
         TypeOperations.minus(self.string2, self.string1)
Ejemplo n.º 29
0
 def test_plus_two_numbers(self):
     expr = TypeOperations.plus(self.number1, self.number2)
     self.assertEqual(8, expr.value)
     self.assertEqual("3 + 5", expr.name)
Ejemplo n.º 30
0
 def equal(self, expr1: BasicExpression, expr2: BasicExpression):
     return TypeOperations.equals(expr1, expr2)