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)


@@ -1204,32 +1204,238 @@
 ot_equal(a, b)%0A%0A
+    def test_nan_array(self):%0A        %22%22%22Test two arrays with different shapes are found not equal.%22%22%22%0A        a = N.array(%5B1, 2%5D)%0A        b = N.array(%5B%5B1, 2%5D, %5B1, 2%5D%5D)%0A%0A        self._test_not_equal(a, b)%0A%0A
     def test_str
@@ -1719,12 +1719,445 @@
 qual(c, b)%0A%0A
+    def test_recarrays(self):%0A        %22%22%22Test record arrays.%22%22%22%0A        a = N.empty(2, %5B('floupi', N.float), ('floupa', N.float)%5D)%0A        a%5B'floupi'%5D = %5B1, 2%5D%0A        a%5B'floupa'%5D = %5B1, 2%5D%0A        b = a.copy()%0A%0A        self._test_equal(a, b)%0A%0A        c = N.empty(2, %5B('floupipi', N.float), ('floupa', N.float)%5D)%0A        c%5B'floupipi'%5D = a%5B'floupi'%5D.copy()%0A        c%5B'floupa'%5D = a%5B'floupa'%5D.copy()%0A%0A        self._test_not_equal(c, b)%0A%0A

Test assert* funcs for arrays with Nan and rec arrays.