# Path: molmod/test/common.py
# class BaseTestCase(unittest.TestCase):
#     def assertArraysEqual(self, a, b):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         assert (a==b).all(), "The array values do not match."
# 
#     def assertArrayConstant(self, arr, const):
#         assert (arr==const).all(), "Some/All array values do not match the constant."
# 
#     def assertArraysAlmostEqual(self, a, b, threshold=1e-6, mean=False, doabs=False):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         if a.shape == (0,):
#             return
#         if mean:
#             abserr = abs(a-b).mean()
#             oom = 0.5*(abs(a).mean()+abs(b).mean())
#         else:
#             abserr = abs(a-b).max()
#             oom = 0.5*(abs(a).max()+abs(b).max())
#         if doabs:
#             assert abserr <= threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, threshold)
#         else:
#             relerr = abserr/oom
#             assert relerr <= threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, threshold)
# 
#     def assertArrayAlmostConstant(self, arr, const, relerr_threshold):
#         error = abs(arr-const).max()
#         oom = const
#         relerr = error/oom
#         assert relerr <= relerr_threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, relerr_threshold)
# 
#     def assertArrayAlmostZero(self, arr, abserr_threshold):
#         abserr = abs(arr).max()
#         assert abserr <= abserr_threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, abserr_threshold)


import numpy as np
import pytest
        import pylab
from molmod.test.common import BaseTestCase
from molmod import *
        from matplotlib.patches import Circle, Polygon
        from matplotlib.lines import Line2D
            fractional = uc.to_fractional(cartesian)
            for i in range(10):
                fractional_bis = uc.to_fractional(cartesian[i])
                self.assertArraysAlmostEqual(fractional[i], fractional_bis)

    def test_to_cartesian(self):
        for i in range(100):
            uc = get_random_uc()
            cartesian = np.random.uniform(-3, 3, 3)
            fractional = cartesian[0]*uc.reciprocal[0] + cartesian[1]*uc.reciprocal[1] + cartesian[2]*uc.reciprocal[2]
            cartesian_bis = uc.to_cartesian(fractional)
            self.assertArraysAlmostEqual(cartesian, cartesian_bis)
        for i in range(100):
            uc = get_random_uc()
            fractional = np.random.uniform(-0.5, 0.5, (10,3))
            cartesian = uc.to_cartesian(fractional)
            for i in range(10):
                cartesian_bis = uc.to_cartesian(fractional[i])
                self.assertArraysAlmostEqual(cartesian[i], cartesian_bis)

    def test_consistency(self):
        for i in range(100):
            uc = get_random_uc()
            cartesian = np.random.uniform(-3, 3, 3)
            fractional = uc.to_fractional(cartesian)
            cartesian_bis = uc.to_cartesian(fractional)
            self.assertArraysAlmostEqual(cartesian, cartesian_bis)
        for i in range(100):
            uc = get_random_uc()
            fractional = np.random.uniform(-0.5, 0.5, (10,3))

# Path: molmod/test/common.py
# class BaseTestCase(unittest.TestCase):
#     def assertArraysEqual(self, a, b):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         assert (a==b).all(), "The array values do not match."
# 
#     def assertArrayConstant(self, arr, const):
#         assert (arr==const).all(), "Some/All array values do not match the constant."
# 
#     def assertArraysAlmostEqual(self, a, b, threshold=1e-6, mean=False, doabs=False):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         if a.shape == (0,):
#             return
#         if mean:
#             abserr = abs(a-b).mean()
#             oom = 0.5*(abs(a).mean()+abs(b).mean())
#         else:
#             abserr = abs(a-b).max()
#             oom = 0.5*(abs(a).max()+abs(b).max())
#         if doabs:
#             assert abserr <= threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, threshold)
#         else:
#             relerr = abserr/oom
#             assert relerr <= threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, threshold)
# 
#     def assertArrayAlmostConstant(self, arr, const, relerr_threshold):
#         error = abs(arr-const).max()
#         oom = const
#         relerr = error/oom
#         assert relerr <= relerr_threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, relerr_threshold)
# 
#     def assertArrayAlmostZero(self, arr, abserr_threshold):
#         abserr = abs(arr).max()
#         assert abserr <= abserr_threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, abserr_threshold)


# Path: molmod/test/test_unit_cells.py
import numpy as np
import pytest
        import pylab
from molmod.test.common import BaseTestCase
from molmod import *
        from matplotlib.patches import Circle, Polygon
        from matplotlib.lines import Line2D

            fractional = uc.to_fractional(cartesian)
            for i in range(10):
                fractional_bis = uc.to_fractional(cartesian[i])
                self.assertArraysAlmostEqual(fractional[i], fractional_bis)

    def test_to_cartesian(self):
        for i in range(100):
            uc = get_random_uc()
            cartesian = np.random.uniform(-3, 3, 3)
            fractional = cartesian[0]*uc.reciprocal[0] + cartesian[1]*uc.reciprocal[1] + cartesian[2]*uc.reciprocal[2]
            cartesian_bis = uc.to_cartesian(fractional)
            self.assertArraysAlmostEqual(cartesian, cartesian_bis)
        for i in range(100):
            uc = get_random_uc()
            fractional = np.random.uniform(-0.5, 0.5, (10,3))
            cartesian = uc.to_cartesian(fractional)
            for i in range(10):
                cartesian_bis = uc.to_cartesian(fractional[i])
                self.assertArraysAlmostEqual(cartesian[i], cartesian_bis)

    def test_consistency(self):
        for i in range(100):
            uc = get_random_uc()
            cartesian = np.random.uniform(-3, 3, 3)
            fractional = uc.to_fractional(cartesian)
            cartesian_bis = uc.to_cartesian(fractional)
            self.assertArraysAlmostEqual(cartesian, cartesian_bis)
        for i in range(100):
            uc = get_random_uc()
            fractional = np.random.uniform(-0.5, 0.5, (10,3))

            cartesian = uc.to_cartesian(fractional)