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))
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())
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})')
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))
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')
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')
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])
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])