Ejemplo n.º 1
0
 def testUnitSystem(self):
     """ Tests the creation of a UnitSystem and its behavior """
     us = u.UnitSystem([
         u.ScaledUnit(1.0, u.coulomb / u.second, 'ampere', 'A'),
         u.second_base_unit
     ])
     self.assertEqual(us.express_unit(u.second), u.second)
     self.assertEqual(us.express_unit(u.hour), u.second)
     self.assertNotEqual(u.hour, u.second)
     self.assertEqual(us.express_unit(u.coulomb / u.second), u.ampere)
     self.assertEqual(us.express_unit(u.meter / u.second),
                      u.meter / u.second)
     self.assertEqual(us.express_unit(u.kilometer / u.hour),
                      u.kilometer / u.second)
     x = 100 * u.millimeters
     self.assertEqual(x.value_in_unit_system(u.si_unit_system), 0.1)
     self.assertEqual(x.value_in_unit_system(u.cgs_unit_system), 10.0)
     self.assertAlmostEqual(x.value_in_unit_system(u.md_unit_system), 1e8)
     y = 20 * u.millimeters / u.millisecond**2
     self.assertAlmostEqual(y.value_in_unit_system(u.si_unit_system), 2e4)
     self.assertAlmostEqual(y.value_in_unit_system(u.cgs_unit_system), 2e6)
     self.assertAlmostEqual(y.value_in_unit_system(u.md_unit_system),
                            2e-11,
                            places=18)
     kcal = 1 * u.md_kilocalorie / u.mole
     self.assertEqual(kcal.value_in_unit_system(u.md_unit_system), 4.184)
Ejemplo n.º 2
0
 def testScaledUnit(self):
     """ Tests ScaledUnit class with kilokelvins """
     kK = u.ScaledUnit(1000.0, u.kelvin, "kilokelvin", "kK")
     self.assertIs(kK.master, u.kelvin)
     self.assertEqual(kK.factor, 1000)
     self.assertEqual(str(kK), 'kilokelvin')
     self.assertEqual(kK.name, 'kilokelvin')
     self.assertEqual(kK.symbol, 'kK')
Ejemplo n.º 3
0
 def testCreateNewScaledUnit(self):
     """ Tests creating a new ScaledUnit """
     mC = u.milli * u.ScaledUnit(4.184, u.joule, "calorie", "cal")
     self.assertIsInstance(mC, u.ScaledUnit)
     self.assertEqual(
         repr(mC),
         "ScaledUnit(factor=0.004184, master=joule, name='millicalorie',"
         " symbol='mcal')")
     self.assertFalse(u.is_unit(mC))