test_{field,value}.py: test complex number RHS for binary operations
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 29 Jun 2019 16:16:38 +0000 (12:16 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 3 Jul 2019 01:31:27 +0000 (21:31 -0400)
This patch adds injected tests for numeric field and value test cases in
which the RHS operand of the tested binary operations is a complex
number, both `-23+19j` and `0j`.

This is to ensure that a binary operator applied to a field object or a
value object and a Python complex number returns what's expected by the
langage, so you can do:

    print(my_field + 8+4.2j)

if you wish.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5cade062e285752d0a917a8b751824b0ebc97f16
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1587
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
tests/bindings/python/bt2/test_field.py
tests/bindings/python/bt2/test_value.py

index 015be10ec1ed9588862434231cc95e2d893b35ea..03235cc35c9e811d31d900bda20124e9f285c66d 100644 (file)
@@ -351,6 +351,12 @@ class _TestNumericField:
     def _test_binop_rhs_zero_vfloat(self, test_cb, op):
         test_cb(op, bt2.create_value(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_type_false(self, op):
         self._test_binop_rhs_false(self._test_binop_type, op)
 
@@ -393,6 +399,12 @@ class _TestNumericField:
     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)
 
@@ -435,6 +447,12 @@ class _TestNumericField:
     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)
 
@@ -477,6 +495,12 @@ class _TestNumericField:
     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)
 
@@ -519,6 +543,12 @@ class _TestNumericField:
     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))
 
@@ -688,6 +718,14 @@ def _inject_numeric_testing_methods(cls):
         setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_vfloat, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_float, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_vfloat, op=binop))
+        setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericField._test_binop_type_complex, op=binop))
+        setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericField._test_binop_type_zero_complex, op=binop))
+        setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericField._test_binop_value_complex, op=binop))
+        setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericField._test_binop_value_zero_complex, op=binop))
+        setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_complex, op=binop))
+        setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_complex, op=binop))
+        setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_complex, op=binop))
+        setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_complex, op=binop))
 
     # inject testing methods for each unary operation
     for name, unaryop in _UNARYOPS:
index 75c89de95d96e1b46d284434ed86ffe153032fef..ca4957161cc65946d6a7c399cfc73be340a32acd 100644 (file)
@@ -262,6 +262,12 @@ class _TestNumericValue(_TestCopySimple):
     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))
 
@@ -313,6 +319,12 @@ class _TestNumericValue(_TestCopySimple):
     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)
 
@@ -355,6 +367,12 @@ class _TestNumericValue(_TestCopySimple):
     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)
 
@@ -397,6 +415,12 @@ class _TestNumericValue(_TestCopySimple):
     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)
 
@@ -439,6 +463,12 @@ class _TestNumericValue(_TestCopySimple):
     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))
 
@@ -602,6 +632,14 @@ def _inject_numeric_testing_methods(cls):
         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:
This page took 0.027121 seconds and 4 git commands to generate.