summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorArink Verma <arinkverma@gmail.com>2013-09-17 23:37:32 +0530
committerCharles Harris <charlesr.harris@gmail.com>2013-09-22 11:34:25 -0600
commit2a303f659c0ad91e0b128811a482683cf9dfaff6 (patch)
treee03a4fc7a8cc1d4fc30b389453d9ee4d4e5bbf66 /numpy
parent764274fc8ffff769a9c7ac2024345467b00319fd (diff)
downloadnumpy-2a303f659c0ad91e0b128811a482683cf9dfaff6.tar.gz
Moved test_multiarra_relational_operators to test_multiarray.py
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_multiarray.py42
-rw-r--r--numpy/core/tests/test_scalarmath.py92
2 files changed, 76 insertions, 58 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index ee773ef4a..7d907caa8 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -3418,6 +3418,48 @@ class TestArrayAttributeDeletion(object):
for s in attr:
assert_raises(AttributeError, delattr, a, s)
+
+ def test_multiarra_relational_operators(self):
+ #All integer
+ for dt1 in np.typecodes['AllInteger']:
+ assert_(1 > np.array(0, dtype=dt1)[()], "type %s failed" % (dt1,))
+ assert_(not 1 < np.array(0, dtype=dt1)[()], "type %s failed" % (dt1,))
+
+ for dt2 in np.typecodes['AllInteger']:
+ assert_(np.array(1, dtype=dt1)[()] > np.array(0, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(not np.array(1, dtype=dt1)[()] < np.array(0, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+
+ #Unsigned integers
+ for dt1 in 'BHILQP':
+ assert_(-1 < np.array(1, dtype=dt1)[()], "type %s failed" % (dt1,))
+ assert_(not -1 > np.array(1, dtype=dt1)[()], "type %s failed" % (dt1,))
+ assert_(-1 != np.array(1, dtype=dt1)[()], "type %s failed" % (dt1,))
+
+ #unsigned vs signed
+ for dt2 in 'bhilqp':
+ assert_(np.array(1, dtype=dt1)[()] > np.array(-1, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(not np.array(1, dtype=dt1)[()] < np.array(-1, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(np.array(1, dtype=dt1)[()] != np.array(-1, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+
+ #Signed integers and floats
+ for dt1 in 'bhlqp'+np.typecodes['Float']:
+ assert_(1 > np.array(-1, dtype=dt1)[()], "type %s failed" % (dt1,))
+ assert_(not 1 < np.array(-1, dtype=dt1)[()], "type %s failed" % (dt1,))
+ assert_(-1 == np.array(-1, dtype=dt1)[()], "type %s failed" % (dt1,))
+
+ for dt2 in 'bhlqp'+np.typecodes['Float']:
+ assert_(np.array(1, dtype=dt1)[()] > np.array(-1, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(not np.array(1, dtype=dt1)[()] < np.array(-1, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(np.array(-1, dtype=dt1)[()] == np.array(-1, dtype=dt2)[()],
+ "type %s and %s failed" % (dt1, dt2))
+
def test_array_interface():
# Test scalar coercion within the array interface
class Foo(object):
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index db4c47d30..b82b3a495 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -162,71 +162,47 @@ class TestConversion(TestCase):
for code in 'lLqQ':
assert_raises(OverflowError, Overflow_error_func, code)
+
def test_int_relational_operation(self):
#All integer
- for code in np.typecodes['AllInteger']:
- assert_(1 > np.array(0, dtype=code), "type %s failed" % (code,))
- assert_(not 1 < np.array(0, dtype=code), "type %s failed" % (code,))
+ for dt1 in np.typecodes['AllInteger']:
+ assert_(1 > np.array(0, dtype=dt1), "type %s failed" % (dt1,))
+ assert_(not 1 < np.array(0, dtype=dt1), "type %s failed" % (dt1,))
- for code2 in np.typecodes['AllInteger']:
- assert_(np.array(1, dtype=code) > np.array(0, dtype=code2), "type %s and %s failed" % (code, code2))
- assert_(not np.array(1, dtype=code) < np.array(0, dtype=code2), "type %s and %s failed" % (code, code2))
+ for dt2 in np.typecodes['AllInteger']:
+ assert_(np.array(1, dtype=dt1) > np.array(0, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(not np.array(1, dtype=dt1) < np.array(0, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
#Unsigned integers
- for code in 'BHILQP':
- assert_(1 < np.array(-1, dtype=code), "type %s failed" % (code,))
- assert_(not 1 > np.array(-1, dtype=code), "type %s failed" % (code,))
- assert_(-1 != np.array(-1, dtype=code), "type %s failed" % (code,))
-
- for code2 in 'BHILQP':
- assert_(np.array(1, dtype=code) < np.array(-1, dtype=code2), "type %s and %s failed" % (code, code2))
- assert_(not np.array(1, dtype=code) > np.array(-1, dtype=code2), "type %s and %s failed" % (code, code2))
- assert_(np.array(1, dtype=code) != np.array(-1, dtype=code2), "type %s and %s failed" % (code, code2))
+ for dt1 in 'BHILQP':
+ assert_(-1 < np.array(1, dtype=dt1), "type %s failed" % (dt1,))
+ assert_(not -1 > np.array(1, dtype=dt1), "type %s failed" % (dt1,))
+ assert_(-1 != np.array(1, dtype=dt1), "type %s failed" % (dt1,))
+
+ #unsigned vs signed
+ for dt2 in 'bhilqp':
+ assert_(np.array(1, dtype=dt1) > np.array(-1, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(not np.array(1, dtype=dt1) < np.array(-1, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(np.array(1, dtype=dt1) != np.array(-1, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
#Signed integers and floats
- for code in 'bhlqp'+np.typecodes['Float']:
- assert_(1 > np.array(-1, dtype=code), "type %s failed" % (code,))
- assert_(not 1 < np.array(-1, dtype=code), "type %s failed" % (code,))
- assert_(-1 == np.array(-1, dtype=code), "type %s failed" % (code,))
-
- for code2 in 'bhlqp'+np.typecodes['Float']:
- assert_(np.array(1, dtype=code) > np.array(-1, dtype=code2), "type %s and %s failed" % (code, code2))
- assert_(not np.array(1, dtype=code) < np.array(-1, dtype=code2), "type %s and %s failed" % (code, code2))
- assert_(np.array(-1, dtype=code) == np.array(-1, dtype=code2), "type %s and %s failed" % (code, code2))
-
-
- def test_scalar_relational_operators(self):
- #All integer
- for code in np.typecodes['AllInteger']:
- assert_(1 > np.array(0, dtype=code)[()], "type %s failed" % (code,))
- assert_(not 1 < np.array(0, dtype=code)[()], "type %s failed" % (code,))
-
- for code2 in np.typecodes['AllInteger']:
- assert_(np.array(1, dtype=code)[()] > np.array(0, dtype=code2)[()], "type %s and %s failed" % (code, code2))
- assert_(not np.array(1, dtype=code)[()] < np.array(0, dtype=code2)[()], "type %s and %s failed" % (code, code2))
-
- #Unsigned integers
- for code in 'BHILQP':
- assert_(1 < np.array(-1, dtype=code)[()], "type %s failed" % (code,))
- assert_(not 1 > np.array(-1, dtype=code)[()], "type %s failed" % (code,))
- assert_(-1 != np.array(-1, dtype=code)[()], "type %s failed" % (code,))
-
- for code2 in 'BHILQP':
- assert_(np.array(1, dtype=code)[()] < np.array(-1, dtype=code2)[()], "type %s and %s failed" % (code, code2))
- assert_(not np.array(1, dtype=code)[()] > np.array(-1, dtype=code2)[()], "type %s and %s failed" % (code, code2))
- assert_(np.array(1, dtype=code)[()] != np.array(-1, dtype=code2)[()], "type %s and %s failed" % (code, code2))
-
- #Signed integers and floats
- for code in 'bhlqp'+np.typecodes['Float']:
- assert_(1 > np.array(-1, dtype=code)[()], "type %s failed" % (code,))
- assert_(not 1 < np.array(-1, dtype=code)[()], "type %s failed" % (code,))
- assert_(-1 == np.array(-1, dtype=code)[()], "type %s failed" % (code,))
-
- for code2 in 'bhlqp'+np.typecodes['Float']:
- assert_(np.array(1, dtype=code)[()] > np.array(-1, dtype=code2)[()], "type %s and %s failed" % (code, code2))
- assert_(not np.array(1, dtype=code)[()] < np.array(-1, dtype=code2)[()], "type %s and %s failed" % (code, code2))
- assert_(np.array(-1, dtype=code)[()] == np.array(-1, dtype=code2)[()], "type %s and %s failed" % (code, code2))
-
+ for dt1 in 'bhlqp'+np.typecodes['Float']:
+ assert_(1 > np.array(-1, dtype=dt1), "type %s failed" % (dt1,))
+ assert_(not 1 < np.array(-1, dtype=dt1), "type %s failed" % (dt1,))
+ assert_(-1 == np.array(-1, dtype=dt1), "type %s failed" % (dt1,))
+
+ for dt2 in 'bhlqp'+np.typecodes['Float']:
+ assert_(np.array(1, dtype=dt1) > np.array(-1, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(not np.array(1, dtype=dt1) < np.array(-1, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
+ assert_(np.array(-1, dtype=dt1) == np.array(-1, dtype=dt2),
+ "type %s and %s failed" % (dt1, dt2))
#class TestRepr(TestCase):