2 if sys
.path
[0] != "../..":
3 sys
.path
.insert(0, "../..")
10 class UnitTestCase(unittest
.TestCase
):
12 def testTrueUnits(self
):
13 self
.failUnlessAlmostEqual(unit
.tom(unit
.t_m
*42), 42)
14 self
.failUnlessAlmostEqual(unit
.tocm(unit
.t_cm
*42), 42)
15 self
.failUnlessAlmostEqual(unit
.tomm(unit
.t_mm
*42), 42)
16 self
.failUnlessAlmostEqual(unit
.toinch(unit
.t_inch
*42), 42)
17 self
.failUnlessAlmostEqual(unit
.topt(unit
.t_pt
*42), 42)
19 def testUserUnits(self
):
21 self
.failUnlessAlmostEqual(unit
.tom(unit
.m
*42), 84)
22 self
.failUnlessAlmostEqual(unit
.tocm(unit
.cm
*42), 84)
23 self
.failUnlessAlmostEqual(unit
.tomm(unit
.mm
*42), 84)
24 self
.failUnlessAlmostEqual(unit
.toinch(unit
.inch
*42), 84)
25 self
.failUnlessAlmostEqual(unit
.topt(unit
.pt
*42), 84)
28 def testVisualUnits(self
):
30 self
.failUnlessAlmostEqual(unit
.tom(unit
.v_m
*42), 126)
31 self
.failUnlessAlmostEqual(unit
.tocm(unit
.v_cm
*42), 126)
32 self
.failUnlessAlmostEqual(unit
.tomm(unit
.v_mm
*42), 126)
33 self
.failUnlessAlmostEqual(unit
.toinch(unit
.v_inch
*42), 126)
34 self
.failUnlessAlmostEqual(unit
.topt(unit
.v_pt
*42), 126)
37 def testWidthUnits(self
):
39 self
.failUnlessAlmostEqual(unit
.tom(unit
.w_m
*42), 168)
40 self
.failUnlessAlmostEqual(unit
.tocm(unit
.w_cm
*42), 168)
41 self
.failUnlessAlmostEqual(unit
.tomm(unit
.w_mm
*42), 168)
42 self
.failUnlessAlmostEqual(unit
.toinch(unit
.w_inch
*42), 168)
43 self
.failUnlessAlmostEqual(unit
.topt(unit
.w_pt
*42), 168)
46 def testTeXUnits(self
):
48 self
.failUnlessAlmostEqual(unit
.tom(unit
.x_m
*42), 210)
49 self
.failUnlessAlmostEqual(unit
.tocm(unit
.x_cm
*42), 210)
50 self
.failUnlessAlmostEqual(unit
.tomm(unit
.x_mm
*42), 210)
51 self
.failUnlessAlmostEqual(unit
.toinch(unit
.x_inch
*42), 210)
52 self
.failUnlessAlmostEqual(unit
.topt(unit
.x_pt
*42), 210)
55 def testMixedUnits(self
):
56 unit
.set(uscale
=2, vscale
=3, wscale
=4, xscale
=5)
57 self
.failUnlessAlmostEqual(unit
.tom(42*unit
.t_m
+ 42*unit
.m
+ 42*unit
.v_m
+ 42*unit
.w_m
+ 42*unit
.x_m
), 630)
58 self
.failUnlessAlmostEqual(unit
.tocm(42*unit
.t_cm
+ 42*unit
.cm
+ 42*unit
.v_cm
+ 42*unit
.w_cm
+ 42*unit
.x_cm
), 630)
59 self
.failUnlessAlmostEqual(unit
.toinch(42*unit
.t_inch
+ 42*unit
.inch
+ 42*unit
.v_inch
+ 42*unit
.w_inch
+ 42*unit
.x_inch
), 630)
60 self
.failUnlessAlmostEqual(unit
.topt(42*unit
.t_pt
+ 42*unit
.pt
+ 42*unit
.v_pt
+ 42*unit
.w_pt
+ 42*unit
.x_pt
), 630)
61 unit
.set(uscale
=1, vscale
=1, wscale
=1, xscale
=1)
63 def testCompareUnits(self
):
64 assert unit
.cm
*41 < unit
.cm
*42, "comparision error"
65 assert unit
.cm
*42 == unit
.cm
*42, "numbers should be equal (might be unstable)"
66 assert unit
.cm
*43 > unit
.cm
*42, "comparision error"
67 assert unit
.cm
*41 < 42, "comparision error"
68 assert unit
.cm
*42 == 42, "numbers should be equal (might be unstable)"
69 assert unit
.cm
*43 > 42, "comparision error"
70 assert 42 > unit
.cm
*41, "comparision error"
71 assert 42 == unit
.cm
*42, "numbers should be equal (might be unstable)"
72 assert 42 < unit
.cm
*43, "comparision error"
75 if __name__
== "__main__":