def test_division(self): """division should error when working with offset units""" w = units.PhysicalQuantity('2kg') x = units.PhysicalQuantity('1g') y = units.PhysicalQuantity('2s') z = units.PhysicalQuantity('1 degC') quo = w.unit/x.unit quo2 = x.unit/y.unit self.assertEqual(quo,units.PhysicalUnit({'kg': 1, 'g': -1}, 1000.0, _get_powers(),0)) self.assertEqual(quo2,units.PhysicalUnit({'s': -1, 'g': 1}, 0.001, _get_powers(mass=1, time=-1),0)) quo = y.unit/2.0 self.assertEqual(quo,units.PhysicalUnit({'s': 1, "2.0":-1}, .5, _get_powers(time=1), 0)) quo = 2.0/y.unit self.assertEqual(quo,units.PhysicalUnit({'s': -1,"2.0":1},2, _get_powers(time=-1),0)) try: x.unit / z.unit except TypeError,err: self.assertEqual(str(err),"cannot divide units with non-zero offset")
def test_multiply(self): """multiplication should error for units with offsets""" x = units.PhysicalQuantity('1g') y = units.PhysicalQuantity('2s') z = units.PhysicalQuantity('1 degC') self.assertEqual( x.unit * y.unit, units.PhysicalUnit({ 's': 1, 'kg': 1 }, .001, _get_powers(mass=1, time=1), 0)) self.assertEqual( y.unit * x.unit, units.PhysicalUnit({ 's': 1, 'kg': 1 }, .001, _get_powers(mass=1, time=1), 0)) try: x.unit * z.unit except TypeError, err: self.assertEqual(str(err), "cannot multiply units with non-zero offset")