Esempio n. 1
0
 def testIsUnit(self):
     """ Tests the unit.is_unit introspective function """
     self.assertTrue(u.is_unit(u.meters))
     self.assertFalse(u.is_unit(None))
     self.assertFalse(u.is_unit(10))
     # Distinguish between "units" and "quantities"
     self.assertFalse(u.is_unit(1 * u.meters))
Esempio n. 2
0
 def testUnitDivision(self):
     """ Tests the division of units and is_dimensionless """
     mps = u.meter / u.second
     mpm = u.meter / u.meter
     mpc = u.meter / u.centimeter
     self.assertTrue(u.is_unit(mps))
     self.assertTrue(u.is_unit(mpm))
     self.assertTrue(u.is_unit(mpc))
     self.assertFalse(mps.is_dimensionless())
     self.assertTrue(mpm.is_dimensionless())
     self.assertTrue(mpc.is_dimensionless())
Esempio n. 3
0
 def testCreateNewUnit(self):
     """ Tests creating a new Unit """
     ms = u.milli * u.second
     self.assertTrue(u.is_unit(ms))
     self.assertEqual(
         repr(ms), 'Unit({BaseUnit(base_dim=BaseDimension("time"), '
         'name="millisecond", symbol="ms"): 1.0})')
Esempio n. 4
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))
Esempio n. 5
0
 def testCompositeUnits(self):
     """ Tests the creation of a composite unit """
     mps = u.Unit({u.meter_base_unit: 1.0, u.second_base_unit: -1.0})
     self.assertTrue(u.is_unit(mps))
     self.assertEqual(str(mps), 'meter/second')
Esempio n. 6
0
 def testBaseScaleMix(self):
     """ Test mixing of BaseUnit and ScaledUnit instances """
     kgj = u.kilogram * u.joule
     self.assertTrue(u.is_unit(kgj))
     self.assertEqual(str(kgj.sqrt()), 'kilogram*meter/second')