Exemplo n.º 1
0
    def test_in_units_of(self):
        #in_units_of should return a new PhysicalQuantity with the requested
        #unit, leaving the old unit as it was

        x = PhysicalQuantity('5cm')
        y = x.in_units_of('m')
        self.assertEqual(y, PhysicalQuantity('0.05m'))
        self.assertEqual(x, PhysicalQuantity('5cm'))

        x = PhysicalQuantity('5cm')
        try:
            y = x.in_units_of('degC')
        except TypeError as err:
            self.assertEqual(str(err), 'Incompatible units')
        else:
            self.fail("TypeError expected")
Exemplo n.º 2
0
    def test_in_units_of(self):
        #in_units_of should return a new PhysicalQuantity with the requested
        #unit, leaving the old unit as it was

        x = PhysicalQuantity('5cm')
        y = x.in_units_of('m')
        self.assertEqual(y, PhysicalQuantity('0.05m'))
        self.assertEqual(x, PhysicalQuantity('5cm'))

        x = PhysicalQuantity('5cm')
        try:
            y = x.in_units_of('degC')
        except TypeError as err:
            self.assertEqual(str(err), 'Incompatible units')
        else:
            self.fail("TypeError expected")