from functools import partial, partialmethod
import operator
+import collections
import unittest
import numbers
import math
def _test_binop_rhs_zero_float(self, test_cb, op):
test_cb(op, 0.0)
+ def _test_binop_rhs_complex(self, test_cb, op):
+ test_cb(op, -23+19j)
+
+ def _test_binop_rhs_zero_complex(self, test_cb, op):
+ test_cb(op, 0j)
+
def _test_binop_rhs_pos_vfloat(self, test_cb, op):
test_cb(op, bt2.create_value(2.2))
def _test_binop_type_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_type, op)
+ def _test_binop_type_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_type, op)
+
+ def _test_binop_type_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_type, op)
+
def _test_binop_value_false(self, op):
self._test_binop_rhs_false(self._test_binop_value, op)
def _test_binop_value_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_value, op)
+ def _test_binop_value_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_value, op)
+
+ def _test_binop_value_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_value, op)
+
def _test_binop_lhs_addr_same_false(self, op):
self._test_binop_rhs_false(self._test_binop_lhs_addr_same, op)
def _test_binop_lhs_addr_same_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_lhs_addr_same, op)
+ def _test_binop_lhs_addr_same_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_lhs_addr_same, op)
+
+ def _test_binop_lhs_addr_same_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_lhs_addr_same, op)
+
def _test_binop_lhs_value_same_false(self, op):
self._test_binop_rhs_false(self._test_binop_lhs_value_same, op)
def _test_binop_lhs_value_same_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_lhs_value_same, op)
+ def _test_binop_lhs_value_same_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_lhs_value_same, op)
+
+ def _test_binop_lhs_value_same_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_lhs_value_same, op)
+
def test_bool_op(self):
self.assertEqual(bool(self._def), bool(self._def_value))
setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_vfloat, op=binop))
setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_float, op=binop))
setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vfloat, op=binop))
+ setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericValue._test_binop_type_complex, op=binop))
+ setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericValue._test_binop_type_zero_complex, op=binop))
+ setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericValue._test_binop_value_complex, op=binop))
+ setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericValue._test_binop_value_zero_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_complex, op=binop))
# inject testing methods for each unary operation
for name, unaryop in _UNARYOPS:
v = bt2.create_value(a)
-class BoolValueTestCase(_TestCopySimple, unittest.TestCase):
+class BoolValueTestCase(_TestNumericValue, unittest.TestCase):
def setUp(self):
self._f = bt2.BoolValue(False)
self._t = bt2.BoolValue(True)
self.assertNotEqual(self._t, False)
+_inject_numeric_testing_methods(BoolValueTestCase)
+
+
class _TestIntegerValue(_TestNumericValue):
def setUp(self):
self._pv = 23
a2 = bt2.ArrayValue(copy.deepcopy(raw))
self.assertEqual(a1, a2)
+ def test_eq_non_sequence_iterable(self):
+ dct = collections.OrderedDict([(1, 2), (3, 4), (5, 6)])
+ a = bt2.ArrayValue((1, 3, 5))
+ self.assertEqual(a, list(dct.keys()))
+ self.assertNotEqual(a, dct)
+
def test_setitem_int(self):
raw = 19
self._def[2] = raw