Esempio n. 1
0
 def test_direct_operator_use(self):
     x, y, z = 423, 324, 321
     res = "(((423 + 324) + (324 + 321)) - (423 + 324)) + (324 + 321)"
     f1 = FieldExpression(x, y, ops.add)
     f2 = FieldExpression(y, z, ops.add)
     f3 = ((f1 + f2) - f1) + f2
     self.assertTrue(f3.eval() == 1290)
     self.assertTrue(f3.to_string() == res)
Esempio n. 2
0
 def test_partly_evaluation(self):
     x, y = 123, "varname"
     f1 = FieldExpression(x, y, ops.add)
     f2 = f1.eval()
     self.assertTrue(isinstance(f1.eval(), FieldExpression))
     self.assertTrue(f1.to_string() == "123 + varname")
     f1.context["varname"] = 313
     self.assertTrue(isinstance(f1.eval(), int))
     self.assertTrue(f1.eval() == 436)
Esempio n. 3
0
 def test_multi_level(self):
     x, y, z = 423, 324, 321
     f1 = FieldExpression(x, y, ops.add)
     f2 = FieldExpression(y, z, ops.add)
     f3 = FieldExpression(f1, f2, ops.sub)
     self.assertTrue(f3.eval() == ops.sub(ops.add(x, y), ops.add(y, z)))
     self.assertTrue(f3.to_string() == "(423 + 324) - (324 + 321)")
Esempio n. 4
0
 def test_simple_exp_add(self):
     x, y = 1, 2
     for o in [ops.add, ops.sub, ops.and_, ops.or_, ops.eq, ops.lt, ops.le]:
         f1 = FieldExpression(x, y, o)
         self.assertTrue(f1.eval() == o(x, y), "failed: {}, ref: {}". \
                 format(o.__name__, o(x, y)))
Esempio n. 5
0
 def __mul__(self, other):
     return FieldExpression(self, other, operator.mul)
Esempio n. 6
0
 def __div__(self, other):
     return FieldExpression(self, other, operator.div)
Esempio n. 7
0
 def __add__(self, other):
     return FieldExpression(self, other, operator.add)
Esempio n. 8
0
 def __sub__(self, other):
     return FieldExpression(self, other, operator.sub)
Esempio n. 9
0
 def __or__(self, other):
     return FieldExpression(self, other, operator.or_)
Esempio n. 10
0
 def __invert__(self):
     return FieldExpression(self, None, operator.inv) 
Esempio n. 11
0
 def __len__(self):
     return FieldExpression(self, None, len)
Esempio n. 12
0
 def __contains__(self, other):
     return FieldExpression(self, other, operator.contains)
Esempio n. 13
0
 def __ge__(self, other):
     return FieldExpression(self, other, operator.ge)
Esempio n. 14
0
 def __eq__(self, other):
     return FieldExpression(self, other, operator.eq)
Esempio n. 15
0
 def __lt__(self, other):
     return FieldExpression(self, other, operator.lt)