Exemplo n.º 1
0
        x2 = units.PhysicalQuantity("1kg")
        y = 1 / x1
        self.assertEqual(y.unit.name(), "1/m")
        y = 1 / x1 / x1
        self.assertEqual(y.unit.name(), "1/m**2")
        y = x1 ** 2
        self.assertEqual(y.unit.name(), "m**2")
        y = x2 / (x1 ** 2)
        self.assertEqual(y.unit.name(), "kg/m**2")


class test__moduleFunctions(unittest.TestCase):
    def test_add_unit(self):
        try:
            units.add_unit("ft", "20*m")
        except KeyError, err:
            self.assertEqual(str(err), "'Unit ft already defined with different factor or powers'")
        else:
            self.fail("Expecting Key Error")

        try:
            units.add_offset_unit("degR", "degK", 20, 10)
        except KeyError, err:
            self.assertEqual(str(err), "'Unit degR already defined with different factor or powers'")
        else:
            self.fail("Expecting Key Error")


if __name__ == "__main__":
    unittest.main()
        x1=units.PhysicalQuantity('1m')
        x2 = units.PhysicalQuantity('1kg')
        y=1/x1
        self.assertEqual(y.unit.name(),'1/m')
        y=1/x1/x1
        self.assertEqual(y.unit.name(),'1/m**2')
        y=x1**2
        self.assertEqual(y.unit.name(),'m**2')
        y=x2/(x1**2)
        self.assertEqual(y.unit.name(),'kg/m**2')


class test__moduleFunctions(unittest.TestCase):
    def test_add_unit(self):
        try:
            units.add_unit('ft','20*m')
        except KeyError,err: 
            self.assertEqual(str(err),"'Unit ft already defined with different factor or powers'")
        else:
            self.fail("Expecting Key Error")
            
        try:
            units.add_offset_unit('degR','degK',20,10)
        except KeyError,err: 
            self.assertEqual(str(err),"'Unit degR already defined with different factor or powers'")
        else:
            self.fail("Expecting Key Error")            

if __name__ == "__main__":
    unittest.main()
Exemplo n.º 3
0
        x1=units.PhysicalQuantity('1m')
        x2 = units.PhysicalQuantity('1kg')
        y=1/x1
        self.assertEqual(y.unit.name(),'1/m')
        y=1/x1/x1
        self.assertEqual(y.unit.name(),'1/m**2')
        y=x1**2
        self.assertEqual(y.unit.name(),'m**2')
        y=x2/(x1**2)
        self.assertEqual(y.unit.name(),'kg/m**2')


class test__moduleFunctions(unittest.TestCase):        
    def test_add_unit(self):
        try:
            units.add_unit('ft','20*m')
        except KeyError,err: 
            self.assertEqual(str(err),"'Unit ft already defined with different factor or powers'")
        else:
            self.fail("Expecting Key Error")
            
        try:
            units.add_offset_unit('degR','degK',20,10)
        except KeyError,err: 
            self.assertEqual(str(err),"'Unit degR already defined with different factor or powers'")
        else:
            self.fail("Expecting Key Error")            

if __name__ == "__main__":
    unittest.main()