1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import numpy as N
from numpy.testing.utils import *
class TestEqual:
def _test_equal(self, a, b):
assert_array_equal(a, b)
def _test_not_equal(self, a, b):
passed = False
try:
assert_array_equal(a, b)
passed = True
except AssertionError:
pass
if passed:
raise AssertionError("a and b are found equal but are not")
def test_array_rank1_eq(self):
"""Test two equal array of rank 1 are found equal."""
a = N.array([1, 2])
b = N.array([1, 2])
self._test_equal(a, b)
def test_array_rank1_noteq(self):
"""Test two different array of rank 1 are found not equal."""
a = N.array([1, 2])
b = N.array([2, 2])
self._test_not_equal(a, b)
def test_array_rank2_eq(self):
"""Test two equal array of rank 2 are found equal."""
a = N.array([[1, 2], [3, 4]])
b = N.array([[1, 2], [3, 4]])
self._test_equal(a, b)
def test_array_diffshape(self):
"""Test two arrays with different shapes are found not equal."""
a = N.array([1, 2])
b = N.array([[1, 2], [1, 2]])
self._test_not_equal(a, b)
def test_string_arrays(self):
"""Test two arrays with different shapes are found not equal."""
a = N.array(['floupi', 'floupa'])
b = N.array(['floupi', 'floupa'])
self._test_equal(a, b)
c = N.array(['floupipi', 'floupa'])
self._test_not_equal(c, b)
|