def setUp(self): """ A function run before each unit test in this class. """ self.Tdata = numpy.array([300,400,500,600,700,800,900,1000,1500,2000], numpy.float64) self.kdata = numpy.array([4.73e-19,3.93e-17,6.51e-16,4.60e-15,2.03e-14,6.28e-14,1.58e-13,3.31e-13,3.72e-12,1.49e-11], numpy.float64) self.Tmin = 300. self.Tmax = 3000. self.comment = 'H + CH4 <=> H2 + CH3 (RPMD)' self.kinetics = KineticsData( Tdata = (self.Tdata,"K"), kdata = (self.kdata,"cm^3/(molecule*s)"), Tmin = (self.Tmin,"K"), Tmax = (self.Tmax,"K"), comment = self.comment, )
class TestKineticsData(unittest.TestCase): """ Contains unit tests of the :class:`KineticsData` class. """ def setUp(self): """ A function run before each unit test in this class. """ self.Tdata = numpy.array([300,400,500,600,700,800,900,1000,1500,2000], numpy.float64) self.kdata = numpy.array([4.73e-19,3.93e-17,6.51e-16,4.60e-15,2.03e-14,6.28e-14,1.58e-13,3.31e-13,3.72e-12,1.49e-11], numpy.float64) self.Tmin = 300. self.Tmax = 3000. self.comment = 'H + CH4 <=> H2 + CH3 (RPMD)' self.kinetics = KineticsData( Tdata = (self.Tdata,"K"), kdata = (self.kdata,"cm^3/(molecule*s)"), Tmin = (self.Tmin,"K"), Tmax = (self.Tmax,"K"), comment = self.comment, ) def test_Tdata(self): """ Test that the KineticsData Tdata property was properly set. """ self.assertEqual(self.kinetics.Tdata.value_si.shape, self.Tdata.shape) for T, T0 in zip(self.kinetics.Tdata.value_si, self.Tdata): self.assertAlmostEqual(T, T0, 4) def test_kdata(self): """ Test that the KineticsData kdata property was properly set. """ self.assertEqual(self.kinetics.kdata.value_si.shape, self.kdata.shape) for k, k0 in zip(self.kinetics.kdata.value_si, self.kdata): k0 *= constants.Na * 1e-6 self.assertAlmostEqual(k, k0, delta=1e-6*k0) def test_Tmin(self): """ Test that the KineticsData Tmin property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmin.value_si, self.Tmin, 6) def test_Tmax(self): """ Test that the KineticsData Tmax property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmax.value_si, self.Tmax, 6) def test_comment(self): """ Test that the KineticsData comment property was properly set. """ self.assertEqual(self.kinetics.comment, self.comment) def test_isTemperatureValid(self): """ Test the KineticsData.isTemperatureValid() method. """ Tdata = numpy.array([200,400,600,800,1000,1200,1400,1600,1800,2000]) validdata = numpy.array([False,True,True,True,True,True,True,True,True,True], numpy.bool) for T, valid in zip(Tdata, validdata): valid0 = self.kinetics.isTemperatureValid(T) self.assertEqual(valid0, valid) def test_getRateCoefficient(self): """ Test the KineticsData.getRateCoefficient() method. """ Tlist = numpy.array([300,400,600,800,1000,1200,1400,1600,1800,2000]) kexplist = numpy.array([2.84847e-01, 2.36670e+01, 2.77019e+03, 3.78191e+04, 1.99333e+05, 5.24644e+05, 1.38086e+06, 2.95680e+06, 5.15086e+06, 8.97299e+06]) for T, kexp in zip(Tlist, kexplist): kact = self.kinetics.getRateCoefficient(T) self.assertAlmostEqual(kexp, kact, delta=1e-4*kexp) def test_pickle(self): """ Test that a KineticsData object can be pickled and unpickled with no loss of information. """ import cPickle kinetics = cPickle.loads(cPickle.dumps(self.kinetics)) self.assertEqual(self.kinetics.Tdata.value.shape, kinetics.Tdata.value.shape) for T, T0 in zip(self.kinetics.Tdata.value, kinetics.Tdata.value): self.assertAlmostEqual(T, T0, 4) self.assertEqual(self.kinetics.Tdata.units, kinetics.Tdata.units) self.assertEqual(self.kinetics.kdata.value.shape, kinetics.kdata.value.shape) for k, k0 in zip(self.kinetics.kdata.value, kinetics.kdata.value): self.assertAlmostEqual(k, k0, 4) self.assertEqual(self.kinetics.kdata.units, kinetics.kdata.units) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment) def test_repr(self): """ Test that a KineticsData object can be reconstructed from its repr() output with no loss of information. """ kinetics = None exec('kinetics = {0!r}'.format(self.kinetics)) self.assertEqual(self.kinetics.Tdata.value.shape, kinetics.Tdata.value.shape) for T, T0 in zip(self.kinetics.Tdata.value, kinetics.Tdata.value): self.assertAlmostEqual(T, T0, 4) self.assertEqual(self.kinetics.Tdata.units, kinetics.Tdata.units) self.assertEqual(self.kinetics.kdata.value.shape, kinetics.kdata.value.shape) for k, k0 in zip(self.kinetics.kdata.value, kinetics.kdata.value): self.assertAlmostEqual(k, k0, 4) self.assertEqual(self.kinetics.kdata.units, kinetics.kdata.units) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment)
class TestKineticsData(unittest.TestCase): """ Contains unit tests of the :class:`KineticsData` class. """ def setUp(self): """ A function run before each unit test in this class. """ self.Tdata = numpy.array([300,400,500,600,700,800,900,1000,1500,2000], numpy.float64) self.kdata = numpy.array([4.73e-19,3.93e-17,6.51e-16,4.60e-15,2.03e-14,6.28e-14,1.58e-13,3.31e-13,3.72e-12,1.49e-11], numpy.float64) self.Tmin = 300. self.Tmax = 3000. self.comment = 'H + CH4 <=> H2 + CH3 (RPMD)' self.kinetics = KineticsData( Tdata = (self.Tdata,"K"), kdata = (self.kdata,"cm^3/(molecule*s)"), Tmin = (self.Tmin,"K"), Tmax = (self.Tmax,"K"), comment = self.comment, ) def test_Tdata(self): """ Test that the KineticsData Tdata property was properly set. """ self.assertEqual(self.kinetics.Tdata.value_si.shape, self.Tdata.shape) for T, T0 in zip(self.kinetics.Tdata.value_si, self.Tdata): self.assertAlmostEqual(T, T0, 4) def test_kdata(self): """ Test that the KineticsData kdata property was properly set. """ self.assertEqual(self.kinetics.kdata.value_si.shape, self.kdata.shape) for k, k0 in zip(self.kinetics.kdata.value_si, self.kdata): k0 *= constants.Na * 1e-6 self.assertAlmostEqual(k, k0, delta=1e-6*k0) def test_Tmin(self): """ Test that the KineticsData Tmin property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmin.value_si, self.Tmin, 6) def test_Tmax(self): """ Test that the KineticsData Tmax property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmax.value_si, self.Tmax, 6) def test_comment(self): """ Test that the KineticsData comment property was properly set. """ self.assertEqual(self.kinetics.comment, self.comment) def test_isTemperatureValid(self): """ Test the KineticsData.isTemperatureValid() method. """ Tdata = numpy.array([200,400,600,800,1000,1200,1400,1600,1800,2000]) validdata = numpy.array([False,True,True,True,True,True,True,True,True,True], numpy.bool) for T, valid in zip(Tdata, validdata): valid0 = self.kinetics.isTemperatureValid(T) self.assertEqual(valid0, valid) def test_getRateCoefficient(self): """ Test the KineticsData.getRateCoefficient() method. """ Tlist = numpy.array([300,400,600,800,1000,1200,1400,1600,1800,2000]) kexplist = numpy.array([2.84847e-01, 2.36670e+01, 2.77019e+03, 3.78191e+04, 1.99333e+05, 5.24644e+05, 1.38086e+06, 2.95680e+06, 5.15086e+06, 8.97299e+06]) for T, kexp in zip(Tlist, kexplist): kact = self.kinetics.getRateCoefficient(T) self.assertAlmostEqual(kexp, kact, delta=1e-4*kexp) def test_pickle(self): """ Test that a KineticsData object can be pickled and unpickled with no loss of information. """ import cPickle kinetics = cPickle.loads(cPickle.dumps(self.kinetics,-1)) self.assertEqual(self.kinetics.Tdata.value.shape, kinetics.Tdata.value.shape) for T, T0 in zip(self.kinetics.Tdata.value, kinetics.Tdata.value): self.assertAlmostEqual(T, T0, 4) self.assertEqual(self.kinetics.Tdata.units, kinetics.Tdata.units) self.assertEqual(self.kinetics.kdata.value.shape, kinetics.kdata.value.shape) for k, k0 in zip(self.kinetics.kdata.value, kinetics.kdata.value): self.assertAlmostEqual(k, k0, 4) self.assertEqual(self.kinetics.kdata.units, kinetics.kdata.units) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment) def test_repr(self): """ Test that a KineticsData object can be reconstructed from its repr() output with no loss of information. """ kinetics = None exec('kinetics = {0!r}'.format(self.kinetics)) self.assertEqual(self.kinetics.Tdata.value.shape, kinetics.Tdata.value.shape) for T, T0 in zip(self.kinetics.Tdata.value, kinetics.Tdata.value): self.assertAlmostEqual(T, T0, 4) self.assertEqual(self.kinetics.Tdata.units, kinetics.Tdata.units) self.assertEqual(self.kinetics.kdata.value.shape, kinetics.kdata.value.shape) for k, k0 in zip(self.kinetics.kdata.value, kinetics.kdata.value): self.assertAlmostEqual(k, k0, 4) self.assertEqual(self.kinetics.kdata.units, kinetics.kdata.units) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment)