def test_energy(self): a = Energy(1.1, "eV") b = a.to("Ha") self.assertAlmostEqual(b, 0.0404242579378) c = Energy(3.14, "J") self.assertAlmostEqual(c.to("eV"), 1.9598339337836966e+19) self.assertRaises(UnitError, Energy, 1, "m") d = Energy(1, "Ha") self.assertAlmostEqual(a + d, 28.31138386) self.assertAlmostEqual(a - d, -26.11138386) self.assertEqual(a + 1, 2.1) self.assertEqual(str(a / d), "1.1 eV Ha^-1")
def test_energy(self): a = Energy(1.1, "eV") b = a.to("Ha") self.assertAlmostEqual(b, 0.0404242579378) c = Energy(3.14, "J") self.assertAlmostEqual(c.to("eV"), 1.9598338493806797e19) self.assertRaises(UnitError, Energy, 1, "m") d = Energy(1, "Ha") self.assertAlmostEqual(a + d, 28.311386245987997) self.assertAlmostEqual(a - d, -26.111386245987994) self.assertEqual(a + 1, 2.1) self.assertEqual(str(a / d), "1.1 eV Ha^-1") e = Energy(1, "kJ") f = e.to("kCal") self.assertAlmostEqual(f, 0.2390057361376673) self.assertEqual(str(e + f), "2.0 kJ") self.assertEqual(str(f + e), "0.4780114722753346 kCal")