2 if sys
.path
[0] != "../..":
3 sys
.path
.insert(0, "../..")
10 class UnitTestCase(unittest
.TestCase
):
12 def testTrueUnits(self
):
13 self
.assertAlmostEqual(unit
.tom(unit
.t_m
*42), 42)
14 self
.assertAlmostEqual(unit
.tocm(unit
.t_cm
*42), 42)
15 self
.assertAlmostEqual(unit
.tomm(unit
.t_mm
*42), 42)
16 self
.assertAlmostEqual(unit
.toinch(unit
.t_inch
*42), 42)
17 self
.assertAlmostEqual(unit
.topt(unit
.t_pt
*42), 42)
19 def testUserUnits(self
):
21 self
.assertAlmostEqual(unit
.tom(unit
.m
*42), 84)
22 self
.assertAlmostEqual(unit
.tocm(unit
.cm
*42), 84)
23 self
.assertAlmostEqual(unit
.tomm(unit
.mm
*42), 84)
24 self
.assertAlmostEqual(unit
.toinch(unit
.inch
*42), 84)
25 self
.assertAlmostEqual(unit
.topt(unit
.pt
*42), 84)
28 def testVisualUnits(self
):
30 self
.assertAlmostEqual(unit
.tom(unit
.v_m
*42), 126)
31 self
.assertAlmostEqual(unit
.tocm(unit
.v_cm
*42), 126)
32 self
.assertAlmostEqual(unit
.tomm(unit
.v_mm
*42), 126)
33 self
.assertAlmostEqual(unit
.toinch(unit
.v_inch
*42), 126)
34 self
.assertAlmostEqual(unit
.topt(unit
.v_pt
*42), 126)
37 def testWidthUnits(self
):
39 self
.assertAlmostEqual(unit
.tom(unit
.w_m
*42), 168)
40 self
.assertAlmostEqual(unit
.tocm(unit
.w_cm
*42), 168)
41 self
.assertAlmostEqual(unit
.tomm(unit
.w_mm
*42), 168)
42 self
.assertAlmostEqual(unit
.toinch(unit
.w_inch
*42), 168)
43 self
.assertAlmostEqual(unit
.topt(unit
.w_pt
*42), 168)
46 def testTeXUnits(self
):
48 self
.assertAlmostEqual(unit
.tom(unit
.x_m
*42), 210)
49 self
.assertAlmostEqual(unit
.tocm(unit
.x_cm
*42), 210)
50 self
.assertAlmostEqual(unit
.tomm(unit
.x_mm
*42), 210)
51 self
.assertAlmostEqual(unit
.toinch(unit
.x_inch
*42), 210)
52 self
.assertAlmostEqual(unit
.topt(unit
.x_pt
*42), 210)
55 def testMixedUnits(self
):
56 unit
.set(uscale
=2, vscale
=3, wscale
=4, xscale
=5)
57 self
.assertAlmostEqual(unit
.tom(42*unit
.t_m
+ 42*unit
.m
+ 42*unit
.v_m
+ 42*unit
.w_m
+ 42*unit
.x_m
), 630)
58 self
.assertAlmostEqual(unit
.tocm(42*unit
.t_cm
+ 42*unit
.cm
+ 42*unit
.v_cm
+ 42*unit
.w_cm
+ 42*unit
.x_cm
), 630)
59 self
.assertAlmostEqual(unit
.toinch(42*unit
.t_inch
+ 42*unit
.inch
+ 42*unit
.v_inch
+ 42*unit
.w_inch
+ 42*unit
.x_inch
), 630)
60 self
.assertAlmostEqual(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__":