# Path: HierMat/grid.py
# class Grid(object):
#     """Discretized grid characterized by points and supports
#     
#     :param points: list of coordinates
#     
#         The points of the discretized Grid.
#             
#     :type points: list[tuple(float)]
#     :param supports: dictionary mapping points with their supports
#     :type supports: dict{point: support}
#     :raise ValueError: if points and supports have different length
#     """
#     def __init__(self, points, supports):
#         """Create a Grid"""
#         # check input
#         if len(points) != len(supports):
#             raise ValueError('points and supports must be of same length')
#         # fill instance
#         self.points = points
#         self.supports = supports
# 
#     def __len__(self):
#         """Return number of points
# 
#         :return: len(points)
#         :rtype: int
#         """
#         return len(self.points)
# 
#     def __getitem__(self, item):
#         """Return point at item
# 
#         :param item: index to return
#         :type item: int
#         """
#         return self.points[item]
# 
#     def __iter__(self):
#         """Iterate trough Grid
#         """
#         return GridIterator(self)
# 
#     def __eq__(self, other):
#         """Test for equality
# 
#         :param other: other grid
#         :type other: Grid
#         :return: True on equality
#         :rtype: bool
#         """
#         points_eq = numpy.array_equal(self.points, other.points)
#         links_eq = numpy.array_equal(self.supports, other.supports)
#         return points_eq and links_eq
# 
#     def __ne__(self, other):
#         """Test for inequality
# 
#         :param other: other grid
#         :type other: Grid
#         :return: True on inequality
#         :rtype: bool
#         """
#         return not self == other
# 
#     def get_point(self, item):
#         """Return point at position item
# 
#         :param item: index
#         :type item: int
#         :return: point
#         """
#         return self.points[item]
# 
#     def get_support(self, item):
#         """Return support for item
# 
#         :param item: point
#         :type item: float or tuple(float)
#         :return: support
#         """
#         return self.supports[item]
# 
#     def get_support_by_index(self, index):
#         """Return support for the i-th item
# 
#         :param index: index
#         :type index: int
#         :return: support
#         """
#         return self.supports[self.get_point(index)]
# 
#     def dim(self):
#         """Dimension of the Grid
#         
#         .. note::
#             
#             this is the dimension of the first point
#              
#              if you store points of different dimensions, this will be misleading
# 
#         :return: dimension
#         :rtype: int
#         """
#         return len(self[0])


import os
import random
import numpy
from unittest import TestCase
from HierMat.grid import Grid




class TestGrid(TestCase):
    @classmethod
    def setUpClass(cls):
        cls.lim1 = 16
        cls.lim2 = 4
        cls.lim3 = 4
        cls.link_num = 2
        cls.points1 = [(float(i) / cls.lim1,) for i in xrange(cls.lim1)]
        cls.links1 = {p: [cls.points1[l] for l in [random.randint(0, cls.lim1 - 1) for x in xrange(cls.link_num)]]
                      for p in cls.points1}
        cls.points2 = [(float(i) / cls.lim2, float(j) / cls.lim2)
                       for i in xrange(cls.lim2) for j in xrange(cls.lim2)]
        cls.links2 = {p: [cls.points2[l] for l in [random.randint(0, cls.lim2 ** 2 - 1) for x in xrange(cls.link_num)]]
                      for p in cls.points2}
        cls.points3 = [(float(i) / cls.lim3, float(j) / cls.lim3, float(k) / cls.lim3)
                       for i in xrange(cls.lim3) for j in xrange(cls.lim3) for k in xrange(cls.lim3)]
        cls.links3 = {p: [cls.points3[l] for l in [random.randint(0, cls.lim3 ** 3 - 1) for x in xrange(cls.link_num)]]
                      for p in cls.points3}
        cls.grid1 = Grid(cls.points1, cls.links1)
        cls.grid2 = Grid(cls.points2, cls.links2)
        cls.grid3 = Grid(cls.points3, cls.links3)

    def test_init(self):

# Path: HierMat/grid.py
# class Grid(object):
#     """Discretized grid characterized by points and supports
#     
#     :param points: list of coordinates
#     
#         The points of the discretized Grid.
#             
#     :type points: list[tuple(float)]
#     :param supports: dictionary mapping points with their supports
#     :type supports: dict{point: support}
#     :raise ValueError: if points and supports have different length
#     """
#     def __init__(self, points, supports):
#         """Create a Grid"""
#         # check input
#         if len(points) != len(supports):
#             raise ValueError('points and supports must be of same length')
#         # fill instance
#         self.points = points
#         self.supports = supports
# 
#     def __len__(self):
#         """Return number of points
# 
#         :return: len(points)
#         :rtype: int
#         """
#         return len(self.points)
# 
#     def __getitem__(self, item):
#         """Return point at item
# 
#         :param item: index to return
#         :type item: int
#         """
#         return self.points[item]
# 
#     def __iter__(self):
#         """Iterate trough Grid
#         """
#         return GridIterator(self)
# 
#     def __eq__(self, other):
#         """Test for equality
# 
#         :param other: other grid
#         :type other: Grid
#         :return: True on equality
#         :rtype: bool
#         """
#         points_eq = numpy.array_equal(self.points, other.points)
#         links_eq = numpy.array_equal(self.supports, other.supports)
#         return points_eq and links_eq
# 
#     def __ne__(self, other):
#         """Test for inequality
# 
#         :param other: other grid
#         :type other: Grid
#         :return: True on inequality
#         :rtype: bool
#         """
#         return not self == other
# 
#     def get_point(self, item):
#         """Return point at position item
# 
#         :param item: index
#         :type item: int
#         :return: point
#         """
#         return self.points[item]
# 
#     def get_support(self, item):
#         """Return support for item
# 
#         :param item: point
#         :type item: float or tuple(float)
#         :return: support
#         """
#         return self.supports[item]
# 
#     def get_support_by_index(self, index):
#         """Return support for the i-th item
# 
#         :param index: index
#         :type index: int
#         :return: support
#         """
#         return self.supports[self.get_point(index)]
# 
#     def dim(self):
#         """Dimension of the Grid
#         
#         .. note::
#             
#             this is the dimension of the first point
#              
#              if you store points of different dimensions, this will be misleading
# 
#         :return: dimension
#         :rtype: int
#         """
#         return len(self[0])


# Path: tests/test_grid.py
import os
import random
import numpy
from unittest import TestCase
from HierMat.grid import Grid





class TestGrid(TestCase):
    @classmethod
    def setUpClass(cls):
        cls.lim1 = 16
        cls.lim2 = 4
        cls.lim3 = 4
        cls.link_num = 2
        cls.points1 = [(float(i) / cls.lim1,) for i in xrange(cls.lim1)]
        cls.links1 = {p: [cls.points1[l] for l in [random.randint(0, cls.lim1 - 1) for x in xrange(cls.link_num)]]
                      for p in cls.points1}
        cls.points2 = [(float(i) / cls.lim2, float(j) / cls.lim2)
                       for i in xrange(cls.lim2) for j in xrange(cls.lim2)]
        cls.links2 = {p: [cls.points2[l] for l in [random.randint(0, cls.lim2 ** 2 - 1) for x in xrange(cls.link_num)]]
                      for p in cls.points2}
        cls.points3 = [(float(i) / cls.lim3, float(j) / cls.lim3, float(k) / cls.lim3)
                       for i in xrange(cls.lim3) for j in xrange(cls.lim3) for k in xrange(cls.lim3)]
        cls.links3 = {p: [cls.points3[l] for l in [random.randint(0, cls.lim3 ** 3 - 1) for x in xrange(cls.link_num)]]
                      for p in cls.points3}
        cls.grid1 = Grid(cls.points1, cls.links1)
        cls.grid2 = Grid(cls.points2, cls.links2)
        cls.grid3 = Grid(cls.points3, cls.links3)

    def test_init(self):

        self.assertEqual(type(self.grid1), Grid)