| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2018, the cclib development team |
| 4 |
# |
| 5 |
# This file is part of cclib (http://cclib.github.io) and is distributed under |
| 6 |
# the terms of the BSD 3-Clause License. |
| 7 |
|
| 8 |
"""Unit tests for parser utils module.""" |
| 9 |
|
| 10 |
import unittest |
| 11 |
|
| 12 |
import cclib |
| 13 |
|
| 14 |
|
| 15 |
class convertorTest(unittest.TestCase): |
| 16 |
|
| 17 |
def test_basic(self): |
| 18 |
"""Are some basic conversions correct?""" |
| 19 |
convertor = cclib.parser.utils.convertor |
| 20 |
self.assertAlmostEqual(convertor(1.89, "bohr", "Angstrom"), 1.0, places=3) |
| 21 |
self.assertAlmostEqual(convertor(0.529, "Angstrom", "bohr"), 1.0, places=3) |
| 22 |
self.assertAlmostEqual(convertor(627.5, "kcal/mol", "hartree"), 1.0, places=3) |
| 23 |
|
| 24 |
def test_pairs(self): |
| 25 |
"""Do flipped conversions correspond to each other?""" |
| 26 |
|
| 27 |
convertor = cclib.parser.utils.convertor |
| 28 |
|
| 29 |
pairs_proportional = ( |
| 30 |
("Angstrom", "bohr"), ("wavenumber", "eV"), |
| 31 |
("wavenumber", "kcal/mol"), ("eV", "kJ/mol"), ("coulomb", "e")) |
| 32 |
pairs_inverse = (("nm", "wavenumber"),) |
| 33 |
|
| 34 |
for unit1, unit2 in pairs_proportional: |
| 35 |
conv1 = convertor(1.0, unit1, unit2) |
| 36 |
conv2 = 1.0 / convertor(1.0, unit2, unit1) |
| 37 |
self.assertAlmostEqual((conv1 - conv2) / conv1, 0.0) |
| 38 |
for unit1, unit2 in pairs_inverse: |
| 39 |
conv1 = convertor(1.0, unit1, unit2) |
| 40 |
conv2 = convertor(1.0, unit2, unit1) |
| 41 |
self.assertAlmostEqual((conv1 - conv2) / conv1, 0.0) |
| 42 |
|
| 43 |
|
| 44 |
class PeriodicTableTest(unittest.TestCase): |
| 45 |
|
| 46 |
def setUp(self): |
| 47 |
self.pt = cclib.parser.utils.PeriodicTable() |
| 48 |
|
| 49 |
def test_elements(self): |
| 50 |
"""Does the periodic table give correct elements?""" |
| 51 |
self.assertEqual(self.pt.element[6], 'C') |
| 52 |
self.assertEqual(self.pt.element[44], 'Ru') |
| 53 |
|
| 54 |
def test_elements(self): |
| 55 |
"""Does the periodic table give correct atom numbers?""" |
| 56 |
self.assertEqual(self.pt.number['C'], 6) |
| 57 |
self.assertEqual(self.pt.number['Au'], 79) |
| 58 |
|
| 59 |
|
| 60 |
if __name__ == "__main__": |
| 61 |
unittest.main() |