Commit f6b63ae6 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Restructured unit tests.

parent 1668499d
......@@ -52,3 +52,12 @@ TAGS
lib/
env/
# CP2K files
*.inp
*.wfn
test/unittests/BASIS_SET
test/unittests/GTH_POTENTIALS
# Setuptools install folder
parser/parser-cp2k/cp2kparser.egg-info/
......@@ -58,45 +58,6 @@ class TestXCFunctional(unittest.TestCase):
self.assertEqual(xc, "GGA_C_LYP_GGA_X_B88")
#===============================================================================
class TestSimulationCell(unittest.TestCase):
def test_from_output(self):
cell = get_result("cell/output_file", "simulation_cell")
n_vectors = cell.shape[0]
n_dim = cell.shape[1]
self.assertEqual(n_vectors, 3)
self.assertEqual(n_dim, 3)
expected_cell = convert_unit(np.array([[6, 0, 0], [0, 6, 0], [0, 0, 6]]), "angstrom")
self.assertTrue(np.array_equal(cell, expected_cell))
#===============================================================================
class TestNumberOfAtoms(unittest.TestCase):
def test_output_file(self):
n_atoms = get_result("particle_number/output_file", "number_of_atoms")
self.assertEqual(n_atoms, 2)
#===============================================================================
class TestAtomPosition(unittest.TestCase):
def test_output_file(self):
atom_position = get_result("atom_position/output_file", "atom_position")
expected_position = convert_unit(np.array([[2.5, 2.5, 2.5]]), "angstrom")
self.assertTrue(np.array_equal(atom_position, expected_position))
#===============================================================================
class TestAtomLabels(unittest.TestCase):
def test_output_file(self):
atom_labels = get_result("atom_label/output_file", "atom_label")
expected_labels = np.array(["Si"])
self.assertTrue(np.array_equal(atom_labels, expected_labels))
#===============================================================================
class TestSectionSCFIteration(unittest.TestCase):
......@@ -114,12 +75,28 @@ class TestSectionSystemDescription(unittest.TestCase):
results = get_results("section_system_description", "section_system_description")
def test_atom_label(self):
for item in self.results.itervalues():
print item
print item.value
# atom_labels = self.results["atom_label"].value
# expected_labels = np.array(8*["Si"])
# self.assertTrue(np.array_equal(atom_labels, expected_labels))
atom_labels = self.results["atom_label"].value
expected_labels = np.array(8*["Si"])
self.assertTrue(np.array_equal(atom_labels, expected_labels))
def test_simulation_cell(self):
cell = self.results["simulation_cell"].value
n_vectors = cell.shape[0]
n_dim = cell.shape[1]
self.assertEqual(n_vectors, 3)
self.assertEqual(n_dim, 3)
expected_cell = convert_unit(np.array([[5.431, 0, 0], [0, 5.431, 0], [0, 0, 5.431]]), "angstrom")
self.assertTrue(np.array_equal(cell, expected_cell))
def test_number_of_atoms(self):
n_atoms = self.results["number_of_atoms"].value
self.assertEqual(n_atoms, 8)
def test_atom_position(self):
atom_position = self.results["atom_position"].value
expected_position = convert_unit(np.array([4.073023, 4.073023, 1.357674]), "angstrom")
self.assertTrue(np.array_equal(atom_position[-1, :], expected_position))
#===============================================================================
if __name__ == '__main__':
......@@ -127,12 +104,8 @@ if __name__ == '__main__':
logger.setLevel(logging.ERROR)
suites = []
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSimulationCell))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestNumberOfAtoms))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestAtomPosition))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestAtomLabels))
# suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSectionSCFIteration))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestXCFunctional))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSectionSCFIteration))
suites.append(unittest.TestLoader().loadTestsFromTestCase(TestSectionSystemDescription))
alltests = unittest.TestSuite(suites)
unittest.TextTestRunner(verbosity=0).run(alltests)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment