# 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 pkg_resources
from molmod.test.common import BaseTestCase
from molmod import *

class SymmetryTestCase(BaseTestCase):
    def test_rotsym_butane(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/butane.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph)
        self.assertEqual(rotsym, 2)

    def test_rotsym_cyclopentane(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/cyclopentane.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph)
        self.assertEqual(rotsym, 1)

    def test_rotsym_octane(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/octane.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)
        self.assertEqual(rotsym, 2)

    def test_rotsym_tetra(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/tetra.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)
        self.assertEqual(rotsym, 12)

    def test_rotsym_water(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/water.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)

# 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_symmetry.py
import pkg_resources
from molmod.test.common import BaseTestCase
from molmod import *


class SymmetryTestCase(BaseTestCase):
    def test_rotsym_butane(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/butane.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph)
        self.assertEqual(rotsym, 2)

    def test_rotsym_cyclopentane(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/cyclopentane.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph)
        self.assertEqual(rotsym, 1)

    def test_rotsym_octane(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/octane.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)
        self.assertEqual(rotsym, 2)

    def test_rotsym_tetra(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/tetra.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)
        self.assertEqual(rotsym, 12)

    def test_rotsym_water(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/water.xyz"))
        molecule.set_default_graph()
        rotsym = compute_rotsym(molecule, molecule.graph, threshold=0.01)

        self.assertEqual(rotsym, 2)