test with no * between number and letter - doctest in operator
This commit is contained in:
parent
6d8d72cdff
commit
8485890fdf
@ -81,24 +81,20 @@ class Operator(str):
|
|||||||
:*args: Operands for this operation
|
:*args: Operands for this operation
|
||||||
:returns: String with operator and his operands
|
:returns: String with operator and his operands
|
||||||
|
|
||||||
>>> mul = Operator("*", 2)
|
>>> op.mul.__txt__('1','2')
|
||||||
>>> add = Operator("+", 2)
|
|
||||||
>>> sub1 = Operator("-", 1)
|
|
||||||
>>> div = Operator("/", 1)
|
|
||||||
>>> mul.__txt__('1','2')
|
|
||||||
'1 * 2'
|
'1 * 2'
|
||||||
>>> add.__txt__('1','2')
|
>>> op.add.__txt__('1','2')
|
||||||
'1 + 2'
|
'1 + 2'
|
||||||
>>> f = save_mainOp('2 + 3',add)
|
>>> f = save_mainOp('2 + 3',op.add)
|
||||||
>>> mul.__txt__(f, '4')
|
>>> op.mul.__txt__(f, '4')
|
||||||
'( 2 + 3 ) * 4'
|
'( 2 + 3 ) * 4'
|
||||||
>>> f = save_mainOp('-3',sub1)
|
>>> f = save_mainOp('-3',op.sub1)
|
||||||
>>> sub1.__txt__(f)
|
>>> op.sub1.__txt__(f)
|
||||||
'- ( -3 )'
|
'- ( -3 )'
|
||||||
>>> sub1.__txt__('-3')
|
>>> op.sub1.__txt__('-3')
|
||||||
'- ( -3 )'
|
'- ( -3 )'
|
||||||
>>> f = save_mainOp('2 + 3',add)
|
>>> f = save_mainOp('2 + 3',op.add)
|
||||||
>>> sub1.__txt__(f)
|
>>> op.sub1.__txt__(f)
|
||||||
'- ( 2 + 3 )'
|
'- ( 2 + 3 )'
|
||||||
"""
|
"""
|
||||||
return self._render(self._txt, *args)
|
return self._render(self._txt, *args)
|
||||||
@ -109,24 +105,20 @@ class Operator(str):
|
|||||||
:*args: Operands for this operation
|
:*args: Operands for this operation
|
||||||
:returns: String with operator and his operands
|
:returns: String with operator and his operands
|
||||||
|
|
||||||
>>> mul = Operator("*", 2)
|
>>> op.mul.__tex__('1','2')
|
||||||
>>> add = Operator("+", 2)
|
|
||||||
>>> sub1 = Operator("-", 1)
|
|
||||||
>>> div = Operator("/", 1)
|
|
||||||
>>> mul.__tex__('1','2')
|
|
||||||
'1 \\\\times 2'
|
'1 \\\\times 2'
|
||||||
>>> add.__tex__('1','2')
|
>>> op.add.__tex__('1','2')
|
||||||
'1 + 2'
|
'1 + 2'
|
||||||
>>> f = save_mainOp('2 + 3',add)
|
>>> f = save_mainOp('2 + 3',op.add)
|
||||||
>>> mul.__tex__(f, '4')
|
>>> op.mul.__tex__(f, '4')
|
||||||
'( 2 + 3 ) \\\\times 4'
|
'( 2 + 3 ) \\\\times 4'
|
||||||
>>> f = save_mainOp('-3',sub1)
|
>>> f = save_mainOp('-3',op.sub1)
|
||||||
>>> sub1.__tex__(f)
|
>>> op.sub1.__tex__(f)
|
||||||
'- ( -3 )'
|
'- ( -3 )'
|
||||||
>>> sub1.__tex__('-3')
|
>>> op.sub1.__tex__('-3')
|
||||||
'- ( -3 )'
|
'- ( -3 )'
|
||||||
>>> f = save_mainOp('2 + 3',add)
|
>>> f = save_mainOp('2 + 3',op.add)
|
||||||
>>> sub1.__tex__(f)
|
>>> op.sub1.__tex__(f)
|
||||||
'- ( 2 + 3 )'
|
'- ( 2 + 3 )'
|
||||||
"""
|
"""
|
||||||
return self._render(self._tex, *args)
|
return self._render(self._tex, *args)
|
||||||
@ -138,21 +130,18 @@ class Operator(str):
|
|||||||
:returns: list with the operator surrounded by operands
|
:returns: list with the operator surrounded by operands
|
||||||
|
|
||||||
# TODO: order doctest |lun. nov. 24 07:17:29 CET 2014
|
# TODO: order doctest |lun. nov. 24 07:17:29 CET 2014
|
||||||
>>> mul = Operator("*", 2)
|
>>> op.mul.__p2i__(1,2)
|
||||||
>>> add = Operator("+", 2)
|
|
||||||
>>> sub1 = Operator("-", 1)
|
|
||||||
>>> mul.__p2i__(1,2)
|
|
||||||
[1, '*', 2]
|
[1, '*', 2]
|
||||||
>>> f = save_mainOp([2, add, 3],add)
|
>>> f = save_mainOp([2, op.add, 3],op.add)
|
||||||
>>> mul.__p2i__(f, 4)
|
>>> op.mul.__p2i__(f, 4)
|
||||||
['(', 2, '+', 3, ')', '*', 4]
|
['(', 2, '+', 3, ')', '*', 4]
|
||||||
>>> f = save_mainOp([sub1, 3],sub1)
|
>>> f = save_mainOp([op.sub1, 3],op.sub1)
|
||||||
>>> sub1.__p2i__(f)
|
>>> op.sub1.__p2i__(f)
|
||||||
['-', '(', '-', 3, ')']
|
['-', '(', '-', 3, ')']
|
||||||
>>> sub1.__p2i__(-3)
|
>>> op.sub1.__p2i__(-3)
|
||||||
['-', '(', -3, ')']
|
['-', '(', -3, ')']
|
||||||
>>> f = save_mainOp([2, add, 3],add)
|
>>> f = save_mainOp([2, op.add, 3],op.add)
|
||||||
>>> sub1.__p2i__(f)
|
>>> op.sub1.__p2i__(f)
|
||||||
['-', '(', 2, '+', 3, ')']
|
['-', '(', 2, '+', 3, ')']
|
||||||
"""
|
"""
|
||||||
# TODO: Attention à gestion des fractions qui se comportent chelou avec les parenthèses |dim. nov. 9 09:21:52 CET 2014
|
# TODO: Attention à gestion des fractions qui se comportent chelou avec les parenthèses |dim. nov. 9 09:21:52 CET 2014
|
||||||
|
@ -98,25 +98,25 @@ class TestPolynom(unittest.TestCase):
|
|||||||
|
|
||||||
def test_reduce(self):
|
def test_reduce(self):
|
||||||
p = Polynom([1, [2, 3], 4])
|
p = Polynom([1, [2, 3], 4])
|
||||||
self.assertEqual(str(p.reduce()[-1]),'4 * x ^ 2 + 5 * x + 1')
|
self.assertEqual(str(p.reduce()[-1]),'4 x ^ 2 + 5 x + 1')
|
||||||
|
|
||||||
def test_add_int(self):
|
def test_add_int(self):
|
||||||
p = Polynom([1, 2, 3])
|
p = Polynom([1, 2, 3])
|
||||||
q = (p + 2)[-1]
|
q = (p + 2)[-1]
|
||||||
self.assertEqual(str(q), '3 * x ^ 2 + 2 * x + 3')
|
self.assertEqual(str(q), '3 x ^ 2 + 2 x + 3')
|
||||||
|
|
||||||
def test_add_frac(self):
|
def test_add_frac(self):
|
||||||
p = Polynom([1, 2, 3])
|
p = Polynom([1, 2, 3])
|
||||||
f = Fraction(1, 2)
|
f = Fraction(1, 2)
|
||||||
q = (p + f)[-1]
|
q = (p + f)[-1]
|
||||||
#ans = repr(Polynom([Expression(Fraction(3, 2)), Expression(2), Expression(3)]))
|
#ans = repr(Polynom([Expression(Fraction(3, 2)), Expression(2), Expression(3)]))
|
||||||
self.assertEqual(str(q),'3 * x ^ 2 + 2 * x + 3 / 2')
|
self.assertEqual(str(q),'3 x ^ 2 + 2 x + 3 / 2')
|
||||||
|
|
||||||
def test_add_poly(self):
|
def test_add_poly(self):
|
||||||
p = Polynom([1, 0, 3])
|
p = Polynom([1, 0, 3])
|
||||||
q = Polynom([0, 2, 3])
|
q = Polynom([0, 2, 3])
|
||||||
r = (p + q)[-1]
|
r = (p + q)[-1]
|
||||||
self.assertEqual(str(r), '6 * x ^ 2 + 2 * x + 1')
|
self.assertEqual(str(r), '6 x ^ 2 + 2 x + 1')
|
||||||
|
|
||||||
def test_radd_int(self):
|
def test_radd_int(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user