示例#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)
示例#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)
示例#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)")
示例#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)))
示例#5
0
 def __mul__(self, other):
     return FieldExpression(self, other, operator.mul)
示例#6
0
 def __div__(self, other):
     return FieldExpression(self, other, operator.div)
示例#7
0
 def __add__(self, other):
     return FieldExpression(self, other, operator.add)
示例#8
0
 def __sub__(self, other):
     return FieldExpression(self, other, operator.sub)
示例#9
0
 def __or__(self, other):
     return FieldExpression(self, other, operator.or_)
示例#10
0
 def __invert__(self):
     return FieldExpression(self, None, operator.inv) 
示例#11
0
 def __len__(self):
     return FieldExpression(self, None, len)
示例#12
0
 def __contains__(self, other):
     return FieldExpression(self, other, operator.contains)
示例#13
0
 def __ge__(self, other):
     return FieldExpression(self, other, operator.ge)
示例#14
0
 def __eq__(self, other):
     return FieldExpression(self, other, operator.eq)
示例#15
0
 def __lt__(self, other):
     return FieldExpression(self, other, operator.lt)