change tex_render into tex and same for txt
This commit is contained in:
parent
7568b42fcc
commit
f04d926031
@ -3,7 +3,7 @@
|
||||
|
||||
from .generic import Stack, flatten_list, expand_list
|
||||
from .fraction import Fraction
|
||||
from .renders import txt_render, post2in_fix, tex_render
|
||||
from .renders import txt, post2in_fix, tex
|
||||
|
||||
__all__ = ['Expression']
|
||||
|
||||
@ -29,8 +29,8 @@ class Expression(object):
|
||||
self.feed_fix() # Determine le fix et range la liste dans self.[fix]_tokens
|
||||
|
||||
def __str__(self):
|
||||
"""Overload str as it aim to be use in console the render is txt_render"""
|
||||
return txt_render(self.postfix_tokens)
|
||||
"""Overload str as it aim to be use in console the render is txt"""
|
||||
return txt(self.postfix_tokens)
|
||||
|
||||
def render(self, render = lambda x:str(x)):
|
||||
""" Same as __str__ but accept render as argument
|
||||
@ -326,8 +326,8 @@ class Expression(object):
|
||||
def test(exp):
|
||||
a = Expression(exp)
|
||||
#for i in a.simplify():
|
||||
#for i in a.simplify(render = txt_render):
|
||||
for i in a.simplify(render = tex_render):
|
||||
#for i in a.simplify(render = txt):
|
||||
for i in a.simplify(render = tex):
|
||||
print(i)
|
||||
|
||||
print("\n")
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
from random import randint
|
||||
from .expression import Expression
|
||||
from .renders import tex_render, txt_render
|
||||
from .renders import tex, txt
|
||||
import re
|
||||
|
||||
from .arithmetic import gcd
|
||||
@ -60,7 +60,7 @@ class RdExpression(object):
|
||||
return varia
|
||||
|
||||
|
||||
def __call__(self, val_min = -10, val_max = 10, render = tex_render):
|
||||
def __call__(self, val_min = -10, val_max = 10, render = tex):
|
||||
"""RdExpression once it is initiate act like a function which create random expressions.
|
||||
|
||||
:param val_min: minimum value random generation
|
||||
@ -134,7 +134,7 @@ def desc_rdExp(rdExp):
|
||||
print("Conditions: ",rdExp._conditions)
|
||||
print("Letters: ", rdExp._letters)
|
||||
print("2replaced: ", rdExp._2replaced)
|
||||
print("Call : ", rdExp(render = tex_render))
|
||||
print("Call : ", rdExp(render = tex))
|
||||
print("Gene varia: ", rdExp._gene_varia)
|
||||
print("Gene 2replaced: ", rdExp._gene_2replaced)
|
||||
print('')
|
||||
|
@ -5,7 +5,7 @@ from .render import Render
|
||||
from .fraction import Fraction
|
||||
from .generic import first_elem, last_elem
|
||||
|
||||
__all__ = ['post2in_fix', 'tex_render', 'txt_render']
|
||||
__all__ = ['post2in_fix', 'tex', 'txt']
|
||||
|
||||
# ------------------------
|
||||
# A infix to postfix list convertor
|
||||
@ -41,7 +41,7 @@ txt_infix = {"+": "+", "-": "-", "*": txtMult, "/" : "/", ":":":", "^":"^"}
|
||||
txt_postfix = {}
|
||||
txt_other = {"(": "(", ")": ")"}
|
||||
|
||||
txt_render = Render(txt_infix, txt_postfix, txt_other)
|
||||
txt = Render(txt_infix, txt_postfix, txt_other)
|
||||
|
||||
# ------------------------
|
||||
# A latex render
|
||||
@ -81,16 +81,16 @@ tex_postfix = {"/": texSlash}
|
||||
tex_other = {"(": "(", ")": ")"}
|
||||
tex_type_render = {str:str, int: str, Fraction: texFrac}
|
||||
|
||||
tex_render = Render(tex_infix, tex_postfix, tex_other, type_render = tex_type_render)
|
||||
tex = Render(tex_infix, tex_postfix, tex_other, type_render = tex_type_render)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#exp = [2, 5, '^', 1, '-', 3, 4, '*', ':']
|
||||
#print(txt_render(exp))
|
||||
#print(txt(exp))
|
||||
#exp = [2, 5, '^', 1, '-', 3, 4, '*', '/', 3, 5, '/', ':']
|
||||
exp = [2, -3, "*"]
|
||||
print(tex_render(exp))
|
||||
print(tex(exp))
|
||||
#exp = [2, 5, '^', 1, '-', 3, 4, '*', '/', 3, '+']
|
||||
#print(post2in_fix(exp))
|
||||
|
||||
|
@ -8,7 +8,7 @@ import unittest
|
||||
from pymath.expression import Expression
|
||||
from pymath.fraction import Fraction
|
||||
from pymath.generic import first_elem
|
||||
from pymath.renders import txt_render
|
||||
from pymath.renders import txt
|
||||
|
||||
|
||||
class TestExpression(unittest.TestCase):
|
||||
|
@ -4,42 +4,42 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from pymath.renders import tex_render, txt_render
|
||||
from pymath.renders import tex, txt
|
||||
from pymath.fraction import Fraction
|
||||
|
||||
|
||||
|
||||
class TestTexRender(unittest.TestCase):
|
||||
"""Testing functions from pymath.renders.tex_render"""
|
||||
"""Testing functions from pymath.renders.tex"""
|
||||
|
||||
def test_type_render_int(self):
|
||||
self.assertEqual(tex_render([2]), "2")
|
||||
self.assertEqual(tex([2]), "2")
|
||||
|
||||
def test_type_render_str(self):
|
||||
self.assertEqual(tex_render(["a"]), "a")
|
||||
self.assertEqual(tex(["a"]), "a")
|
||||
|
||||
def test_type_render_fraction(self):
|
||||
self.assertEqual(tex_render([Fraction(1,2)]), "\\frac{ 1 }{ 2 }")
|
||||
self.assertEqual(tex([Fraction(1,2)]), "\\frac{ 1 }{ 2 }")
|
||||
|
||||
def test_mult_interger(self):
|
||||
exps = [ [2, 3, "*"], [2, -3, "*"], [-2, 3, "*"]]
|
||||
wanted_render = [ "2 \\times 3", "2 \\times ( -3 )", "-2 \\times 3"]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = tex_render(e)
|
||||
rend = tex(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_letter(self):
|
||||
exps = [ [2, "a", "*"], ["a", 3, "*"], [-2, "a", "*"], ["a", -2, "*"]]
|
||||
wanted_render = [ "2 a", "a \\times 3", "-2 a", "a \\times ( -2 )"]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = tex_render(e)
|
||||
rend = tex(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_fraction(self):
|
||||
exps = [ [2, Fraction(1,2), "*"], [Fraction(1,2), 3, "*"]]
|
||||
wanted_render = [ "2 \\times \\frac{ 1 }{ 2 }", "\\frac{ 1 }{ 2 } \\times 3"]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = tex_render(e)
|
||||
rend = tex(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_exp(self):
|
||||
@ -52,36 +52,36 @@ class TestTexRender(unittest.TestCase):
|
||||
|
||||
|
||||
class TesttxtRender(unittest.TestCase):
|
||||
"""Testing functions from pymath.renders.txt_render"""
|
||||
"""Testing functions from pymath.renders.txt"""
|
||||
|
||||
def test_type_render_int(self):
|
||||
self.assertEqual(txt_render([2]), "2")
|
||||
self.assertEqual(txt([2]), "2")
|
||||
|
||||
def test_type_render_str(self):
|
||||
self.assertEqual(txt_render(["a"]), "a")
|
||||
self.assertEqual(txt(["a"]), "a")
|
||||
|
||||
def test_type_render_fraction(self):
|
||||
self.assertEqual(txt_render([Fraction(1,2)]), "1 / 2")
|
||||
self.assertEqual(txt([Fraction(1,2)]), "1 / 2")
|
||||
|
||||
def test_mult_interger(self):
|
||||
exps = [ [2, 3, "*"], [2, -3, "*"], [-2, 3, "*"]]
|
||||
wanted_render = [ "2 * 3", "2 * ( -3 )", "-2 * 3"]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = txt_render(e)
|
||||
rend = txt(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_letter(self):
|
||||
exps = [ [2, "a", "*"], ["a", 3, "*"], [-2, "a", "*"], ["a", -2, "*"]]
|
||||
wanted_render = [ "2 a", "a * 3", "-2 a", "a * ( -2 )"]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = txt_render(e)
|
||||
rend = txt(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_fraction(self):
|
||||
exps = [ [2, Fraction(1,2), "*"], [Fraction(1,2), 3, "*"]]
|
||||
wanted_render = [ "2 * 1 / 2", "1 / 2 * 3"]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = txt_render(e)
|
||||
rend = txt(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_exp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user