fixed a bug in deformer.parallel, reported by Andreas Matthias
[PyX/mjg.git] / test / unit / test_texter.py
blobdd98f7316a75bde29b4651a435c4100c56a92681
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest
7 from pyx import *
8 from pyx.graph.axis.tick import tick
9 from pyx.graph.axis.texter import rational, decimal, exponential, mixed
12 class TexterTestCase(unittest.TestCase):
14 def testFrac(self):
15 ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)]
16 rational(numsuffix=r"\pi").labels(ticks)
17 self.failUnlessEqual([t.label for t in ticks], [r"{{\pi}\over{4}}", r"{{\pi}\over{2}}"])
18 ticks = [tick((0, 3), labellevel=0), tick((3, 3), labellevel=0), tick((6, 3), labellevel=0)]
19 rational(numsuffix=r"\pi").labels(ticks)
20 self.failUnlessEqual([t.label for t in ticks], ["0", r"\pi", r"2\pi"])
21 ticks = [tick((2, 3), labellevel=0), tick((4, 5), labellevel=0)]
22 rational(numsuffix=r"\pi", equaldenom=1).labels(ticks)
23 self.failUnlessEqual([t.label for t in ticks], [r"{{10\pi}\over{15}}", r"{{12\pi}\over{15}}"])
25 def testDec(self):
26 ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)]
27 decimal().labels(ticks)
28 self.failUnlessEqual([t.label for t in ticks], ["0.25", "0.5"])
29 ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)]
30 decimal(equalprecision=1).labels(ticks)
31 self.failUnlessEqual([t.label for t in ticks], ["0.25", "0.50"])
32 ticks = [tick((1, 17), labellevel=0), tick((17, 17), labellevel=0)]
33 decimal().labels(ticks)
34 self.failUnlessEqual([t.label for t in ticks], [r"0.\overline{0588235294117647}", "1"])
35 ticks = [tick((1, 10000000), labellevel=0), tick((1, 100000000), labellevel=0), tick((1, 1000000000), labellevel=0)]
36 decimal(thousandthpartsep=",").labels(ticks)
37 self.failUnlessEqual([t.label for t in ticks], ["0.000,000,1", "0.000,000,01", "0.000,000,001"])
38 ticks = [tick((1000000, 1), labellevel=0), tick((10000000, 1), labellevel=0), tick((100000000, 1), labellevel=0)]
39 decimal(thousandsep=",").labels(ticks)
40 self.failUnlessEqual([t.label for t in ticks], ["1,000,000", "10,000,000", "100,000,000"])
42 def testExp(self):
43 ticks = [tick((-1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10, 1), labellevel=0)]
44 exponential().labels(ticks)
45 self.failUnlessEqual([t.label for t in ticks], [r"{-10^{-1}}", r"{10^{0}}", r"{10^{1}}"])
46 ticks = [tick((0, 1), labellevel=0), tick((1, -10), labellevel=0), tick((15, 100), labellevel=0)]
47 exponential(mantissatexter=decimal(equalprecision=1)).labels(ticks)
48 self.failUnlessEqual([t.label for t in ticks], [r"{0.0}", r"{{-1.0}\cdot10^{-1}}", r"{{1.5}\cdot10^{-1}}"])
50 def testDefault(self):
51 ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10, 1), labellevel=0)]
52 mixed().labels(ticks)
53 self.failUnlessEqual([t.label for t in ticks], ["0", "0.1", "1", "10"])
54 ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10000, 1), labellevel=0)]
55 mixed().labels(ticks)
56 self.failUnlessEqual([t.label for t in ticks], [r"{0}", r"{{1}\cdot10^{-1}}", r"{1}", r"{{1}\cdot10^{4}}"])
57 ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10000, 1), labellevel=0)]
58 mixed(equaldecision=0).labels(ticks)
59 self.failUnlessEqual([t.label for t in ticks], ["0", "0.1", "1", r"{10^{4}}"])
62 if __name__ == "__main__":
63 unittest.main()