Beispiel #1
0
    def testset_preferred_unit(self):
        self.settings.set_preferred_unit(unit_registry.lb)

        q1 = unit_registry.Quantity(1.2, unit_registry.kilogram)
        q2 = self.settings.to_preferred_unit(q1)
        self.assertAlmostEqual(2.645547, q2.magnitude, 4)
        self.assertEqual(unit_registry.lb, q2.units)
Beispiel #2
0
 def testset_preferred_unit_density(self):
     self.settings.set_preferred_unit(unit_registry.kilogram /
                                      unit_registry.meter**3)
     q1 = unit_registry.Quantity(
         1.2, unit_registry.gram / unit_registry.centimeter**3)
     q2 = self.settings.to_preferred_unit(q1)
     self.assertAlmostEqual(1.2e3, q2.magnitude, 4)
     self.assertEqual(unit_registry.kilogram / unit_registry.meter**3,
                      q2.units)
Beispiel #3
0
    def testclear_preferred_units(self):
        self.settings.set_preferred_unit(unit_registry.nanometer)
        q1 = unit_registry.Quantity(1.2, unit_registry.meter)
        q2 = self.settings.to_preferred_unit(q1)
        self.assertAlmostEqual(1.2e9, q2.magnitude, 4)
        self.assertEqual(unit_registry.nanometer, q2.units)

        self.settings.clear_preferred_units()
        q2 = self.settings.to_preferred_unit(q1)
        self.assertAlmostEqual(1.2, q2.magnitude, 4)
        self.assertEqual(unit_registry.meter, q2.units)
Beispiel #4
0
 def testset_preferred_unit_angle(self):
     self.settings.set_preferred_unit(unit_registry.radian)
     q1 = unit_registry.Quantity(1.2, unit_registry.degree)
     q2 = self.settings.to_preferred_unit(q1)
     self.assertAlmostEqual(math.radians(1.2), q2.magnitude, 4)
     self.assertEqual(unit_registry.radian, q2.units)
Beispiel #5
0
 def testset_preferred_unit_energy(self):
     self.settings.set_preferred_unit(unit_registry.joule)
     q1 = unit_registry.Quantity(1.2, unit_registry.electron_volt)
     q2 = self.settings.to_preferred_unit(q1)
     self.assertAlmostEqual(1.2 * physics.e, q2.magnitude, 4)
     self.assertEqual(unit_registry.joule, q2.units)