2014-02-25 15:39:03 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2014-05-28 18:42:19 +00:00
|
|
|
from pymath.renders import tex, txt
|
2014-02-25 15:39:03 +00:00
|
|
|
from pymath.fraction import Fraction
|
2014-11-02 10:12:47 +00:00
|
|
|
from pymath.operator import Operator
|
2014-02-25 15:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTexRender(unittest.TestCase):
|
2014-05-28 18:42:19 +00:00
|
|
|
"""Testing functions from pymath.renders.tex"""
|
2014-02-25 15:39:03 +00:00
|
|
|
|
|
|
|
def test_type_render_int(self):
|
2014-05-28 18:42:19 +00:00
|
|
|
self.assertEqual(tex([2]), "2")
|
2014-02-25 15:39:03 +00:00
|
|
|
|
|
|
|
def test_type_render_str(self):
|
2014-05-28 18:42:19 +00:00
|
|
|
self.assertEqual(tex(["a"]), "a")
|
2014-02-25 15:39:03 +00:00
|
|
|
|
|
|
|
def test_type_render_fraction(self):
|
2014-05-28 18:42:19 +00:00
|
|
|
self.assertEqual(tex([Fraction(1,2)]), "\\frac{ 1 }{ 2 }")
|
2014-02-25 15:39:03 +00:00
|
|
|
|
|
|
|
def test_mult_interger(self):
|
2014-11-02 10:12:47 +00:00
|
|
|
exps = [ [2, 3, Operator("*", 2)], [2, -3, Operator("*", 2)], [-2, 3, Operator("*", 2)]]
|
2014-02-25 15:39:03 +00:00
|
|
|
wanted_render = [ "2 \\times 3", "2 \\times ( -3 )", "-2 \\times 3"]
|
|
|
|
for (i,e) in enumerate(exps):
|
2014-05-28 18:42:19 +00:00
|
|
|
rend = tex(e)
|
2014-02-25 15:39:03 +00:00
|
|
|
self.assertEqual(rend, wanted_render[i])
|
|
|
|
|
|
|
|
def test_mult_letter(self):
|
2014-11-02 10:12:47 +00:00
|
|
|
exps = [ [2, "a", Operator("*", 2)], ["a", 3, Operator("*", 2)], [-2, "a", Operator("*", 2)], ["a", -2, Operator("*", 2)]]
|
2014-02-26 11:48:41 +00:00
|
|
|
wanted_render = [ "2 a", "a \\times 3", "-2 a", "a \\times ( -2 )"]
|
2014-02-25 15:39:03 +00:00
|
|
|
for (i,e) in enumerate(exps):
|
2014-05-28 18:42:19 +00:00
|
|
|
rend = tex(e)
|
2014-02-25 15:39:03 +00:00
|
|
|
self.assertEqual(rend, wanted_render[i])
|
|
|
|
|
|
|
|
def test_mult_fraction(self):
|
2014-11-02 10:12:47 +00:00
|
|
|
exps = [ [2, Fraction(1,2), Operator("*", 2)], [Fraction(1,2), 3, Operator("*", 2)]]
|
2014-02-26 11:48:41 +00:00
|
|
|
wanted_render = [ "2 \\times \\frac{ 1 }{ 2 }", "\\frac{ 1 }{ 2 } \\times 3"]
|
2014-02-25 15:39:03 +00:00
|
|
|
for (i,e) in enumerate(exps):
|
2014-05-28 18:42:19 +00:00
|
|
|
rend = tex(e)
|
2014-02-25 15:39:03 +00:00
|
|
|
self.assertEqual(rend, wanted_render[i])
|
|
|
|
|
|
|
|
def test_mult_exp(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_slash(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TesttxtRender(unittest.TestCase):
|
2014-05-28 18:42:19 +00:00
|
|
|
"""Testing functions from pymath.renders.txt"""
|
2014-02-25 15:39:03 +00:00
|
|
|
|
2014-02-25 15:58:51 +00:00
|
|
|
def test_type_render_int(self):
|
2014-05-28 18:42:19 +00:00
|
|
|
self.assertEqual(txt([2]), "2")
|
2014-02-25 15:58:51 +00:00
|
|
|
|
|
|
|
def test_type_render_str(self):
|
2014-05-28 18:42:19 +00:00
|
|
|
self.assertEqual(txt(["a"]), "a")
|
2014-02-25 15:58:51 +00:00
|
|
|
|
|
|
|
def test_type_render_fraction(self):
|
2014-05-28 18:42:19 +00:00
|
|
|
self.assertEqual(txt([Fraction(1,2)]), "1 / 2")
|
2014-02-25 15:58:51 +00:00
|
|
|
|
|
|
|
def test_mult_interger(self):
|
2014-11-02 10:12:47 +00:00
|
|
|
exps = [ [2, 3, Operator("*", 2)], \
|
|
|
|
[2, -3, Operator("*", 2)], \
|
|
|
|
[-2, 3, Operator("*", 2)]]
|
2014-02-25 15:58:51 +00:00
|
|
|
wanted_render = [ "2 * 3", "2 * ( -3 )", "-2 * 3"]
|
|
|
|
for (i,e) in enumerate(exps):
|
2014-05-28 18:42:19 +00:00
|
|
|
rend = txt(e)
|
2014-02-25 15:58:51 +00:00
|
|
|
self.assertEqual(rend, wanted_render[i])
|
|
|
|
|
|
|
|
def test_mult_letter(self):
|
2014-11-02 10:12:47 +00:00
|
|
|
exps = [ [2, "a", Operator("*", 2)], \
|
|
|
|
["a", 3, Operator("*", 2)], \
|
|
|
|
[-2, "a", Operator("*", 2)], \
|
|
|
|
["a", -2, Operator("*", 2)]]
|
2014-02-26 11:48:41 +00:00
|
|
|
wanted_render = [ "2 a", "a * 3", "-2 a", "a * ( -2 )"]
|
2014-02-25 15:58:51 +00:00
|
|
|
for (i,e) in enumerate(exps):
|
2014-05-28 18:42:19 +00:00
|
|
|
rend = txt(e)
|
2014-02-25 15:58:51 +00:00
|
|
|
self.assertEqual(rend, wanted_render[i])
|
|
|
|
|
|
|
|
def test_mult_fraction(self):
|
2014-11-02 10:12:47 +00:00
|
|
|
exps = [ [2, Fraction(1,2), Operator("*", 2)], \
|
|
|
|
[Fraction(1,2), 3, Operator("*", 2)]]
|
2014-02-25 15:58:51 +00:00
|
|
|
wanted_render = [ "2 * 1 / 2", "1 / 2 * 3"]
|
|
|
|
for (i,e) in enumerate(exps):
|
2014-05-28 18:42:19 +00:00
|
|
|
rend = txt(e)
|
2014-02-25 15:58:51 +00:00
|
|
|
self.assertEqual(rend, wanted_render[i])
|
|
|
|
|
|
|
|
def test_mult_exp(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_slash(self):
|
|
|
|
pass
|
|
|
|
|
2014-02-25 15:39:03 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|
|
|
|
|