# Path: pyhull/convex_hull.py
# class ConvexHull(object):
#     """
#     Convex hull for a set of points.
# 
#     .. attribute: dim
# 
#         Dimension of the points.
# 
#     .. attribute: points
# 
#         Original points supplied.
# 
#     .. attribute: vertices
# 
#         The vertices as a list of list of integer indices. E.g., [[0, 2], [1,
#         0], [2, 3], [3, 1]]
#     """
# 
#     def __init__(self, points, joggle=False):
#         """
#         Initializes a ConvexHull from points.
# 
#         Args:
#             points ([[float]]): All the points as a sequence of sequences.
#                 e.g., [[-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
#             joggle (bool): Use qhull option to joggle inputs until simplical
#                 result is obtained instead of merging facets.
#         """
#         self.points = points
#         dim = [len(i) for i in self.points]
#         if max(dim) != min(dim):
#             raise ValueError("Input points must all have the same dimension!")
#         self.dim = dim[0]
#         if joggle:
#             options = "i QJ"
#         else:
#             options = "i Qt"
#         output = qconvex(options, points)
#         output.pop(0)
#         self.vertices = [[int(i) for i in row.strip().split()]
#                          for row in output]
# 
#     @property
#     def simplices(self):
#         """
#         Returns the simplices of the convex hull.
#         """
#         return [Simplex([self.points[i] for i in v]) for v in self.vertices]


import unittest
import numpy as np
from pyhull.convex_hull import ConvexHull
        #Check that bad points raises an error.
        bad_points = [[0,0], [0,1,0], [0,0]]
        self.assertRaises(ValueError, ConvexHull, bad_points)

    def test_vertices(self):
        expected_ans = [[0, 2], [1, 0], [2, 3], [3, 1]]
        self.assertEqual(self.hull.vertices, expected_ans)
        expected_ans = [[1, 5, 9], [6, 3, 0], [6, 8, 9], [8, 1, 9], [8, 6, 0],
                        [1, 8, 0], [7, 1, 0], [7, 5, 1], [2, 6, 9], [2, 3, 6],
                        [5, 2, 9], [3, 2, 5], [4, 3, 5], [7, 4, 5], [3, 4, 0],
                        [4, 7, 0]]
        self.assertEqual(self.sphull.vertices, expected_ans)
        
    def test_joggle(self):
        joggled_hull = ConvexHull(self.hull.points, joggle=True)
        expected_ans = set([(0, 2), (1, 0), (2, 3), (3, 1)])
        ans = set([tuple(x) for x in joggled_hull.vertices])
        self.assertEqual(ans, expected_ans)
        joggled_sphull = ConvexHull(self.sphull.points, joggle=True)
        expected_ans = set([(1, 5, 9), (6, 3, 0), (6, 8, 9), (8, 1, 9), (8, 6, 0),
                            (1, 8, 0), (7, 1, 0), (7, 5, 1), (2, 6, 9), (2, 3, 6),
                            (5, 2, 9), (3, 2, 5), (4, 3, 5), (7, 4, 5), (3, 4, 0),
                            (4, 7, 0)])
        ans = set([tuple(x) for x in joggled_sphull.vertices])
        self.assertEqual(ans, expected_ans)

    def test_redundant_points(self):
        data = self.hull.points
        expected_ans = [[0, 2], [1, 0], [2, 3], [3, 1]]
        data.extend([[0, -0.5], [0,  0.5], [-0.5, 0], [0.5, 0]])

# Path: pyhull/convex_hull.py
# class ConvexHull(object):
#     """
#     Convex hull for a set of points.
# 
#     .. attribute: dim
# 
#         Dimension of the points.
# 
#     .. attribute: points
# 
#         Original points supplied.
# 
#     .. attribute: vertices
# 
#         The vertices as a list of list of integer indices. E.g., [[0, 2], [1,
#         0], [2, 3], [3, 1]]
#     """
# 
#     def __init__(self, points, joggle=False):
#         """
#         Initializes a ConvexHull from points.
# 
#         Args:
#             points ([[float]]): All the points as a sequence of sequences.
#                 e.g., [[-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
#             joggle (bool): Use qhull option to joggle inputs until simplical
#                 result is obtained instead of merging facets.
#         """
#         self.points = points
#         dim = [len(i) for i in self.points]
#         if max(dim) != min(dim):
#             raise ValueError("Input points must all have the same dimension!")
#         self.dim = dim[0]
#         if joggle:
#             options = "i QJ"
#         else:
#             options = "i Qt"
#         output = qconvex(options, points)
#         output.pop(0)
#         self.vertices = [[int(i) for i in row.strip().split()]
#                          for row in output]
# 
#     @property
#     def simplices(self):
#         """
#         Returns the simplices of the convex hull.
#         """
#         return [Simplex([self.points[i] for i in v]) for v in self.vertices]


# Path: pyhull/tests/test_convex_hull.py
import unittest
import numpy as np
from pyhull.convex_hull import ConvexHull

        #Check that bad points raises an error.
        bad_points = [[0,0], [0,1,0], [0,0]]
        self.assertRaises(ValueError, ConvexHull, bad_points)

    def test_vertices(self):
        expected_ans = [[0, 2], [1, 0], [2, 3], [3, 1]]
        self.assertEqual(self.hull.vertices, expected_ans)
        expected_ans = [[1, 5, 9], [6, 3, 0], [6, 8, 9], [8, 1, 9], [8, 6, 0],
                        [1, 8, 0], [7, 1, 0], [7, 5, 1], [2, 6, 9], [2, 3, 6],
                        [5, 2, 9], [3, 2, 5], [4, 3, 5], [7, 4, 5], [3, 4, 0],
                        [4, 7, 0]]
        self.assertEqual(self.sphull.vertices, expected_ans)
        
    def test_joggle(self):
        joggled_hull = ConvexHull(self.hull.points, joggle=True)
        expected_ans = set([(0, 2), (1, 0), (2, 3), (3, 1)])
        ans = set([tuple(x) for x in joggled_hull.vertices])
        self.assertEqual(ans, expected_ans)
        joggled_sphull = ConvexHull(self.sphull.points, joggle=True)
        expected_ans = set([(1, 5, 9), (6, 3, 0), (6, 8, 9), (8, 1, 9), (8, 6, 0),
                            (1, 8, 0), (7, 1, 0), (7, 5, 1), (2, 6, 9), (2, 3, 6),
                            (5, 2, 9), (3, 2, 5), (4, 3, 5), (7, 4, 5), (3, 4, 0),
                            (4, 7, 0)])
        ans = set([tuple(x) for x in joggled_sphull.vertices])
        self.assertEqual(ans, expected_ans)

    def test_redundant_points(self):
        data = self.hull.points
        expected_ans = [[0, 2], [1, 0], [2, 3], [3, 1]]
        data.extend([[0, -0.5], [0,  0.5], [-0.5, 0], [0.5, 0]])

        self.assertEqual(ConvexHull(data).vertices, expected_ans)