add doctest and unittest for render
This commit is contained in:
parent
cdfd70d3f3
commit
d503db6cef
@ -386,8 +386,14 @@ class op(object):
|
||||
2
|
||||
>>> mul.__tex__('1','2')
|
||||
'1 \\times 2'
|
||||
>>> mul.__tex__('2','a')
|
||||
'2 a'
|
||||
>>> mul.__txt__('1','2')
|
||||
'1 * 2'
|
||||
>>> mul.__txt__('2','a')
|
||||
'2 a'
|
||||
>>> mul.__txt__('a','2')
|
||||
'a * 2'
|
||||
>>> mul.__tex__('1','-2')
|
||||
'1 \\times (-2)'
|
||||
"""
|
||||
@ -514,24 +520,24 @@ class op(object):
|
||||
return caract
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(op.add.__tex__('1','2'))
|
||||
print(op.mul.__tex__('1','2'))
|
||||
print(op.sub.__tex__('1','2'))
|
||||
f = save_mainOp('2 + 3',op.add)
|
||||
print(op.mul.__txt__(f, '4'))
|
||||
f = save_mainOp('-3',op.sub1)
|
||||
print(op.sub1.__txt__(f))
|
||||
print(op.sub1.__txt__('-3'))
|
||||
f = save_mainOp('2 + 3',op.add)
|
||||
print(op.sub1.__txt__(f))
|
||||
#print(op.add.__tex__('1','2'))
|
||||
#print(op.mul.__tex__('1','2'))
|
||||
#print(op.sub.__tex__('1','2'))
|
||||
#f = save_mainOp('2 + 3',op.add)
|
||||
#print(op.mul.__txt__(f, '4'))
|
||||
#f = save_mainOp('-3',op.sub1)
|
||||
#print(op.sub1.__txt__(f))
|
||||
#print(op.sub1.__txt__('-3'))
|
||||
#f = save_mainOp('2 + 3',op.add)
|
||||
#print(op.sub1.__txt__(f))
|
||||
|
||||
from .fraction import Fraction
|
||||
f = Fraction(1, 2)
|
||||
print(op.add.__txt__(f.__txt__(),'2'))
|
||||
print(op.add.__tex__(f.__tex__(),'2'))
|
||||
#from .fraction import Fraction
|
||||
#f = Fraction(1, 2)
|
||||
#print(op.add.__txt__(f.__txt__(),'2'))
|
||||
#print(op.add.__tex__(f.__tex__(),'2'))
|
||||
|
||||
print("\t op.can_be_operator('+') :" + str(op.can_be_operator('+')))
|
||||
print("\t op.can_be_operator('t') :" + str(op.can_be_operator('t')))
|
||||
#print("\t op.can_be_operator('+') :" + str(op.can_be_operator('+')))
|
||||
#print("\t op.can_be_operator('t') :" + str(op.can_be_operator('t')))
|
||||
|
||||
|
||||
import doctest
|
||||
|
@ -55,7 +55,7 @@ class TestTexRender(unittest.TestCase):
|
||||
]
|
||||
wanted_render = [ "2 ( 3 x^{ 2 } + 2 x + 1 )",
|
||||
"( 3 x^{ 2 } + 2 x + 1 ) \\times 2",
|
||||
"( 3 x^{ 2 } + 2 x + 1 ) ( 3 x^{ 2 } + 2 x + 1 )",
|
||||
"( 3 x^{ 2 } + 2 x + 1 ) ( 6 x^{ 2 } + 5 x + 4 )",
|
||||
]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = tex(e)
|
||||
@ -129,11 +129,20 @@ class TesttxtRender(unittest.TestCase):
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_letter(self):
|
||||
exps = [ [2, "a", op.get_op("*", 2)], \
|
||||
["a", 3, op.get_op("*", 2)], \
|
||||
[-2, "a", op.get_op("*", 2)], \
|
||||
["a", -2, op.get_op("*", 2)]]
|
||||
wanted_render = [ "2 a", "a * 3", "-2 a", "a * ( -2 )"]
|
||||
exps = [ [2, "a", op.mul], \
|
||||
["a", 3, op.mul], \
|
||||
[-2, "a", op.mul], \
|
||||
["a", -2, op.mul],
|
||||
["a", -2, op.mul, -2, op.mul],
|
||||
["a", -2, op.mul, "a", op.mul],
|
||||
]
|
||||
wanted_render = [ "2 a",
|
||||
"a * 3",
|
||||
"-2 a",
|
||||
"a * ( -2 )",
|
||||
"a * ( -2 ) * ( -2 )",
|
||||
"a * ( -2 ) a",
|
||||
]
|
||||
for (i,e) in enumerate(exps):
|
||||
rend = txt(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
Loading…
Reference in New Issue
Block a user