# Path: pyamg/gallery/mesh.py
# def regular_triangle_mesh(nx, ny):
#     """Construct a regular triangular mesh in the unit square.
# 
#     Parameters
#     ----------
#     nx : int
#        Number of nodes in the x-direction
#     ny : int
#        Number of nodes in the y-direction
# 
#     Returns
#     -------
#     Vert : array
#         nx*ny x 2 vertex list
#     E2V : array
#         Nex x 3 element list
# 
#     Examples
#     --------
#     >>> from pyamg.gallery import regular_triangle_mesh
#     >>> E2V,Vert = regular_triangle_mesh(3, 2)
# 
#     """
#     nx, ny = int(nx), int(ny)
# 
#     if nx < 2 or ny < 2:
#         raise ValueError(f'minimum mesh dimension is 2: {(nx, ny)}')
# 
#     Vert1 = np.tile(np.arange(0, nx-1), ny - 1) +\
#         np.repeat(np.arange(0, nx * (ny - 1), nx), nx - 1)
#     Vert3 = np.tile(np.arange(0, nx-1), ny - 1) +\
#         np.repeat(np.arange(0, nx * (ny - 1), nx), nx - 1) + nx
#     Vert2 = Vert3 + 1
#     Vert4 = Vert1 + 1
# 
#     Verttmp = np.meshgrid(np.arange(0, nx, dtype='float'),
#                           np.arange(0, ny, dtype='float'))
#     Verttmp = (Verttmp[0].ravel(), Verttmp[1].ravel())
#     Vert = np.vstack(Verttmp).transpose()
#     Vert[:, 0] = (1.0 / (nx - 1)) * Vert[:, 0]
#     Vert[:, 1] = (1.0 / (ny - 1)) * Vert[:, 1]
# 
#     E2V1 = np.vstack((Vert1, Vert2, Vert3)).transpose()
#     E2V2 = np.vstack((Vert1, Vert4, Vert2)).transpose()
#     E2V = np.vstack((E2V1, E2V2))
# 
#     return Vert, E2V


from pyamg.gallery.mesh import regular_triangle_mesh
from numpy.testing import TestCase, assert_equal
"""Test basic mesh construction."""



class TestRegularTriangleMesh(TestCase):
    def test_1x1(self):
        try:
            regular_triangle_mesh(1, 0)
        except ValueError:
            pass
        else:
            raise Exception('regular_triangle_mesh(1,0) should throw an error')

    def test_2x2(self):
        Vert, E2V = regular_triangle_mesh(2, 2)

        assert_equal(Vert, [[0., 0.],
                            [1., 0.],
                            [0., 1.],
                            [1., 1.]])

        assert_equal(E2V, [[0, 3, 2],
                           [0, 1, 3]])

    def test_3x2(self):

# Path: pyamg/gallery/mesh.py
# def regular_triangle_mesh(nx, ny):
#     """Construct a regular triangular mesh in the unit square.
# 
#     Parameters
#     ----------
#     nx : int
#        Number of nodes in the x-direction
#     ny : int
#        Number of nodes in the y-direction
# 
#     Returns
#     -------
#     Vert : array
#         nx*ny x 2 vertex list
#     E2V : array
#         Nex x 3 element list
# 
#     Examples
#     --------
#     >>> from pyamg.gallery import regular_triangle_mesh
#     >>> E2V,Vert = regular_triangle_mesh(3, 2)
# 
#     """
#     nx, ny = int(nx), int(ny)
# 
#     if nx < 2 or ny < 2:
#         raise ValueError(f'minimum mesh dimension is 2: {(nx, ny)}')
# 
#     Vert1 = np.tile(np.arange(0, nx-1), ny - 1) +\
#         np.repeat(np.arange(0, nx * (ny - 1), nx), nx - 1)
#     Vert3 = np.tile(np.arange(0, nx-1), ny - 1) +\
#         np.repeat(np.arange(0, nx * (ny - 1), nx), nx - 1) + nx
#     Vert2 = Vert3 + 1
#     Vert4 = Vert1 + 1
# 
#     Verttmp = np.meshgrid(np.arange(0, nx, dtype='float'),
#                           np.arange(0, ny, dtype='float'))
#     Verttmp = (Verttmp[0].ravel(), Verttmp[1].ravel())
#     Vert = np.vstack(Verttmp).transpose()
#     Vert[:, 0] = (1.0 / (nx - 1)) * Vert[:, 0]
#     Vert[:, 1] = (1.0 / (ny - 1)) * Vert[:, 1]
# 
#     E2V1 = np.vstack((Vert1, Vert2, Vert3)).transpose()
#     E2V2 = np.vstack((Vert1, Vert4, Vert2)).transpose()
#     E2V = np.vstack((E2V1, E2V2))
# 
#     return Vert, E2V


# Path: pyamg/gallery/tests/test_mesh.py
from pyamg.gallery.mesh import regular_triangle_mesh
from numpy.testing import TestCase, assert_equal

"""Test basic mesh construction."""



class TestRegularTriangleMesh(TestCase):
    def test_1x1(self):
        try:
            regular_triangle_mesh(1, 0)
        except ValueError:
            pass
        else:
            raise Exception('regular_triangle_mesh(1,0) should throw an error')

    def test_2x2(self):
        Vert, E2V = regular_triangle_mesh(2, 2)

        assert_equal(Vert, [[0., 0.],
                            [1., 0.],
                            [0., 1.],
                            [1., 1.]])

        assert_equal(E2V, [[0, 3, 2],
                           [0, 1, 3]])

    def test_3x2(self):

        Vert, E2V = regular_triangle_mesh(3, 2)