UnitTests.py
Go to the documentation of this file.00001
00002
00003 import FreeCAD, os, unittest, math
00004
00005
00006
00007
00008
00009
00010 def compare(x,y): return math.fabs(x-y)<0.00001
00011
00012 class UnitBasicCases(unittest.TestCase):
00013
00014 def testConversions(self):
00015 tu = FreeCAD.Units.translateUnit
00016 self.failUnless(compare( tu('10 m') , 10000.0 ) )
00017 self.failUnless(compare( tu('3/8 in') , 0.014763779527 ) )
00018 self.failUnless(compare( tu('100 km/h') , 27777.77777777 ) )
00019 self.failUnless(compare( tu('m^2*kg*s^-3*A^-2') , 1000000.0 ) )
00020 self.failUnless(compare( tu('(m^2*kg)/(A^2*s^3)') , 1000000.0 ) )
00021 self.failUnless(compare( tu('2*pi rad') , 360.0 ) )
00022 self.failUnless(compare( tu('2*pi rad') / tu('gon') , 400.0 ) )
00023
00024 def testImperial(self):
00025 tu = FreeCAD.Units.translateUnit
00026 self.failUnless(compare( tu('3/8 in') , 0.014763779527 ) )
00027 self.failUnless(compare( tu('1fo+(3+7/16)in') , 392.112500 ) )
00028 self.failUnless(compare( tu('1\'+(3+7/16)"') , 392.112500 ) )
00029
00030 def testTrigonometric(self):
00031 tu = FreeCAD.Units.translateUnit
00032 self.failUnless(compare( tu('sin(pi)') , math.sin(math.pi) ) )
00033 self.failUnless(compare( tu('cos(pi)') , math.cos(math.pi) ) )
00034 self.failUnless(compare( tu('tan(pi)') , math.tan(math.pi) ) )
00035
00036
00037
00038