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(unit
.length("42 t m") + unit
.length("42 u m") + unit
.length("42 v m") + unit
.length("42 w m") + unit
.length("42 x m")), 630)
58 self
.failUnlessAlmostEqual(unit
.tocm(unit
.length("42 t cm") + unit
.length("42 u cm") + unit
.length("42 v cm") + unit
.length("42 w cm") + unit
.length("42 x cm")), 630)
59 self
.failUnlessAlmostEqual(unit
.tomm(unit
.length("42 t mm") + unit
.length("42 u mm") + unit
.length("42 v mm") + unit
.length("42 w mm") + unit
.length("42 x mm")), 630)
60 self
.failUnlessAlmostEqual(unit
.toinch(unit
.length("42 t inch") + unit
.length("42 u inch") + unit
.length("42 v inch") + unit
.length("42 w inch") + unit
.length("42 x inch")), 630)
61 self
.failUnlessAlmostEqual(unit
.topt(unit
.length("42 t pt") + unit
.length("42 u pt") + unit
.length("42 v pt") + unit
.length("42 w pt") + unit
.length("42 x pt")), 630)
62 unit
.set(uscale
=1, vscale
=1, wscale
=1, xscale
=1)
64 def testCompareUnits(self
):
65 assert unit
.cm(41) < unit
.cm(42), "comparision error"
66 assert unit
.cm(42) == unit
.cm(42), "numbers should be equal (might be unstable)"
67 assert unit
.cm(43) > unit
.cm(42), "comparision error"
68 assert unit
.cm(41) < 42, "comparision error"
69 assert unit
.cm(42) == 42, "numbers should be equal (might be unstable)"
70 assert unit
.cm(43) > 42, "comparision error"
71 assert 42 > unit
.cm(41), "comparision error"
72 assert 42 == unit
.cm(42), "numbers should be equal (might be unstable)"
73 assert 42 < unit
.cm(43), "comparision error"
76 if __name__
== "__main__":