fixes #0003137: Unit UserString wrong

This commit is contained in:
wmayer
2017-07-24 16:52:03 +02:00
parent 80ad5737f0
commit 7ab8a9996d
3 changed files with 25 additions and 3 deletions

View File

@@ -4,10 +4,16 @@ import FreeCAD
import unittest
import math
def tu(str):
return FreeCAD.Units.Quantity(str).Value
def ts(q):
return q.UserString
def ts2(q):
return FreeCAD.Units.Quantity(q.UserString).UserString
#---------------------------------------------------------------------------
# define the functions to test the FreeCAD UnitApi code
#---------------------------------------------------------------------------
@@ -36,6 +42,14 @@ class UnitBasicCases(unittest.TestCase):
#self.failUnless(compare(tu('1fo(3+7/16)in'),392.112500))thisgivesaparsersyntaxerror!!!
self.failUnless(compare(tu('1\'(3+7/16)"'), 392.112500))
def testSelfConsistency(self):
qu = FreeCAD.Units.Quantity("0.23 W/m/K")
self.assertTrue(ts(qu), ts2(qu))
qu = FreeCAD.Units.Quantity("237 mm*kg/(s^3*K)")
self.assertTrue(ts(qu), ts2(qu))
qu = FreeCAD.Units.Quantity("237.000 W/mm/K")
self.assertTrue(ts(qu), ts2(qu))
def testTrigonometric(self):
#tu=FreeCAD.Units.translateUnit
self.failUnless(compare(tu('sin(pi)'), math.sin(math.pi)))