示例#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))
示例#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())
示例#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})')
示例#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))
示例#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')
示例#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')
示例#7
0
文件: vec3.py 项目: ChayaSt/openmm
 def __rmul__(self, other):
     """Multiply a Vec3 by a constant."""
     if unit.is_unit(other):
         return unit.Quantity(self, other)
     return Vec3(other*self[0], other*self[1], other*self[2])
示例#8
0
 def __rmul__(self, other):
     """Multiply a Vec3 by a constant."""
     if unit.is_unit(other):
         return unit.Quantity(self, other)
     return Vec3(other * self[0], other * self[1], other * self[2])