autopep8 on calculus test
This commit is contained in:
parent
bc4f1fe384
commit
e43544006e
File diff suppressed because one or more lines are too long
@ -4,29 +4,29 @@
|
||||
|
||||
from pymath.calculus import arithmetic
|
||||
|
||||
|
||||
def test_gcd_commu():
|
||||
assert arithmetic.gcd(3, 15) == arithmetic.gcd(15, 3)
|
||||
|
||||
|
||||
def test_gcd1():
|
||||
assert arithmetic.gcd(3, 15) == 3
|
||||
|
||||
|
||||
def test_gcd2():
|
||||
assert arithmetic.gcd(14, 21) == 7
|
||||
|
||||
|
||||
def test_gcd_prem():
|
||||
assert arithmetic.gcd(14, 19) == 1
|
||||
|
||||
|
||||
def test_gcd_neg():
|
||||
assert arithmetic.gcd(3, -15) == 3
|
||||
assert arithmetic.gcd(-3, -15) == -3
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
@ -14,16 +14,20 @@ def test_init_from_str():
|
||||
exp = Expression("2 + 3")
|
||||
assert exp.postfix_tokens == [2, 3, "+"]
|
||||
|
||||
|
||||
def test_init_from_exp():
|
||||
pass
|
||||
|
||||
|
||||
def test_init_list():
|
||||
exp = Expression([2, 3, "+"])
|
||||
assert exp.postfix_tokens == [2, 3, "+"]
|
||||
|
||||
|
||||
def test_init_one_element_int_from_str():
|
||||
exp = Expression("1")
|
||||
|
||||
|
||||
def test_init_one_element_int_from_list():
|
||||
exp = Expression([1])
|
||||
|
||||
@ -33,6 +37,7 @@ def test_init_one_element_int_from_list():
|
||||
# def test_init_one_element_str_from_list():
|
||||
# exp = Expression(["x"])
|
||||
|
||||
|
||||
def test_simplify_exp():
|
||||
exp = Expression("1 + 2 * 3")
|
||||
simplified = exp.simplify()
|
||||
@ -56,18 +61,21 @@ def test_simplify_exp():
|
||||
# '\\frac{ -7 }{ 2 }']
|
||||
# assert simplified.steps == list(exp.simplify())
|
||||
|
||||
|
||||
def test_add_exp():
|
||||
e = Expression("12- 4")
|
||||
f = Expression("4 + 1")
|
||||
g = e + f
|
||||
assert g.postfix_tokens == [12, 4, '-', 4, 1, "+", "+"]
|
||||
|
||||
|
||||
def test_mul_exp():
|
||||
e = Expression("12- 4")
|
||||
f = Expression("4 + 1")
|
||||
g = e * f
|
||||
assert g.postfix_tokens == [12, 4, '-', 4, 1, "+", "*"]
|
||||
|
||||
|
||||
def test_neg_exp():
|
||||
e = Expression("12- 4")
|
||||
g = -e
|
||||
|
@ -5,23 +5,33 @@ import unittest
|
||||
|
||||
from pymath.calculus.fraction import Fraction
|
||||
|
||||
|
||||
class TestFraction(unittest.TestCase):
|
||||
"""Testing functions from pymath.calculus.Fraction"""
|
||||
|
||||
def setUp(self):
|
||||
self.listFrom = [Fraction(1, 3), 1]
|
||||
self.listAgainst = [ Fraction(1,3), \
|
||||
Fraction(2,3), \
|
||||
Fraction(4,5), \
|
||||
Fraction(-1, 3), \
|
||||
Fraction(1,-3), \
|
||||
self.listAgainst = [Fraction(1, 3),
|
||||
Fraction(2, 3),
|
||||
Fraction(4, 5),
|
||||
Fraction(-1, 3),
|
||||
Fraction(1, -3),
|
||||
1,
|
||||
]
|
||||
|
||||
def test_add(self):
|
||||
ans = [[Fraction(2, 3), 1, Fraction(17, 15), 0, 0, Fraction(4,3)], \
|
||||
[Fraction(4,3), Fraction(5,3), Fraction(9,5), Fraction(2,3), Fraction(2,3), 2] \
|
||||
]
|
||||
ans = [
|
||||
[
|
||||
Fraction(
|
||||
2, 3), 1, Fraction(
|
||||
17, 15), 0, 0, Fraction(
|
||||
4, 3)], [
|
||||
Fraction(
|
||||
4, 3), Fraction(
|
||||
5, 3), Fraction(
|
||||
9, 5), Fraction(
|
||||
2, 3), Fraction(
|
||||
2, 3), 2]]
|
||||
|
||||
for (i, f1) in enumerate(self.listFrom):
|
||||
for (j, f2) in enumerate(self.listAgainst):
|
||||
@ -29,8 +39,8 @@ class TestFraction(unittest.TestCase):
|
||||
self.assertEqual(res, ans[i][j])
|
||||
|
||||
def test_sub(self):
|
||||
ans = [[0, Fraction(-1,3), Fraction(-7, 15), Fraction(2,3), Fraction(2,3), Fraction(-2,3)], \
|
||||
[Fraction(2,3), Fraction(1,3), Fraction(1,5), Fraction(4,3), Fraction(4,3), 0] \
|
||||
ans = [[0, Fraction(-1, 3), Fraction(-7, 15), Fraction(2, 3), Fraction(2, 3), Fraction(-2, 3)],
|
||||
[Fraction(2, 3), Fraction(1, 3), Fraction(1, 5), Fraction(4, 3), Fraction(4, 3), 0]
|
||||
]
|
||||
|
||||
for (i, f1) in enumerate(self.listFrom):
|
||||
@ -39,11 +49,11 @@ class TestFraction(unittest.TestCase):
|
||||
self.assertEqual(res, ans[i][j])
|
||||
|
||||
def test_neg(self):
|
||||
ans = [ Fraction(-1,3), \
|
||||
Fraction(-2,3), \
|
||||
Fraction(-4,5), \
|
||||
Fraction(1, 3), \
|
||||
Fraction(1,3), \
|
||||
ans = [Fraction(-1, 3),
|
||||
Fraction(-2, 3),
|
||||
Fraction(-4, 5),
|
||||
Fraction(1, 3),
|
||||
Fraction(1, 3),
|
||||
-1
|
||||
]
|
||||
for (j, f) in enumerate(self.listAgainst):
|
||||
@ -51,9 +61,8 @@ class TestFraction(unittest.TestCase):
|
||||
self.assertEqual(res, ans[j])
|
||||
|
||||
def test_mul(self):
|
||||
ans = [[Fraction(1, 9), Fraction(2,9), Fraction(4, 15), Fraction(-1,9), Fraction(-1,9), Fraction(1,3)], \
|
||||
[ Fraction(1,3), Fraction(2,3), Fraction(4,5), Fraction(-1, 3), Fraction(1,-3), 1] \
|
||||
]
|
||||
ans = [[Fraction(1, 9), Fraction(2, 9), Fraction(4, 15), Fraction(-1, 9), Fraction(-1, 9), Fraction(
|
||||
1, 3)], [Fraction(1, 3), Fraction(2, 3), Fraction(4, 5), Fraction(-1, 3), Fraction(1, -3), 1]]
|
||||
|
||||
for (i, f1) in enumerate(self.listFrom):
|
||||
for (j, f2) in enumerate(self.listAgainst):
|
||||
@ -61,8 +70,8 @@ class TestFraction(unittest.TestCase):
|
||||
self.assertEqual(res, ans[i][j])
|
||||
|
||||
def test_truediv(self):
|
||||
ans = [[1, Fraction(1,2), Fraction(5, 12), -1, -1, Fraction(1,3)], \
|
||||
[3, Fraction(3,2), Fraction(5,4), -3, -3, 1] \
|
||||
ans = [[1, Fraction(1, 2), Fraction(5, 12), -1, -1, Fraction(1, 3)],
|
||||
[3, Fraction(3, 2), Fraction(5, 4), -3, -3, 1]
|
||||
]
|
||||
|
||||
for (i, f1) in enumerate(self.listFrom):
|
||||
|
@ -6,6 +6,7 @@ import unittest
|
||||
|
||||
from pymath.calculus import generic
|
||||
|
||||
|
||||
class TestGeneric(unittest.TestCase):
|
||||
"""Testing functions from pymath.calculus.generic"""
|
||||
|
||||
@ -67,9 +68,6 @@ if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
|
@ -10,22 +10,26 @@ def test_add_render_tex():
|
||||
assert op.add.__tex__('1', '2') == '1 + 2'
|
||||
assert op.add.__tex__('1', '-2') == '1 - 2'
|
||||
|
||||
|
||||
def test_add_render_txt():
|
||||
assert op.add.__txt__('1', '2') == '1 + 2'
|
||||
assert op.add.__txt__('1', '-2') == '1 - 2'
|
||||
|
||||
# Test de op.sub
|
||||
|
||||
|
||||
def test_sub_render_tex():
|
||||
assert op.sub.__tex__('1', '2') == '1 - 2'
|
||||
assert op.sub.__tex__('1', '-2') == '1 - ( -2 )'
|
||||
|
||||
|
||||
def test_sub_render_txt():
|
||||
assert op.sub.__txt__('1', '2') == '1 - 2'
|
||||
assert op.sub.__txt__('1', '-2') == '1 - ( -2 )'
|
||||
|
||||
# Test de op.sub1
|
||||
|
||||
|
||||
def test_sub1_render():
|
||||
assert op.sub1.__tex__('1') == '- 1'
|
||||
assert op.sub1.__tex__('-1') == '- ( -1 )'
|
||||
@ -33,24 +37,28 @@ def test_sub1_render():
|
||||
assert op.sub1.__txt__('-1') == '- ( -1 )'
|
||||
|
||||
# Test de op.mul
|
||||
|
||||
|
||||
def test_mul_render_tex():
|
||||
assert op.mul.__tex__('1', '2') == '1 \\times 2'
|
||||
assert op.mul.__tex__('1', '-2') == '1 \\times ( -2 )'
|
||||
|
||||
|
||||
def test_mul_render_txt():
|
||||
assert op.mul.__txt__('1', '2') == '1 * 2'
|
||||
assert op.mul.__txt__('1', '-2') == '1 * ( -2 )'
|
||||
|
||||
|
||||
def test_mul_is_visible():
|
||||
assert op.mul.is_visible(2,3) == True
|
||||
assert op.mul.is_visible(2,-3) == True
|
||||
assert op.mul.is_visible(-2,3) == True
|
||||
assert op.mul.is_visible('a',2) == True
|
||||
assert op.mul.is_visible('(2a + 1)', 2) == True
|
||||
assert op.mul.is_visible(2, '(-2)') == True
|
||||
assert op.mul.is_visible(2, '2a') == True
|
||||
assert op.mul.is_visible(2, '(-2a)') == True
|
||||
assert op.mul.is_visible(2, '(-2abc)') == True
|
||||
assert op.mul.is_visible(2, 3)
|
||||
assert op.mul.is_visible(2, -3)
|
||||
assert op.mul.is_visible(-2, 3)
|
||||
assert op.mul.is_visible('a', 2)
|
||||
assert op.mul.is_visible('(2a + 1)', 2)
|
||||
assert op.mul.is_visible(2, '(-2)')
|
||||
assert op.mul.is_visible(2, '2a')
|
||||
assert op.mul.is_visible(2, '(-2a)')
|
||||
assert op.mul.is_visible(2, '(-2abc)')
|
||||
|
||||
assert op.mul.is_visible(2, 'a') == False
|
||||
assert op.mul.is_visible(2, '(2a + 1)') == False
|
||||
@ -58,31 +66,33 @@ def test_mul_is_visible():
|
||||
assert op.mul.is_visible(2, '(-2x + 1)(3x + 2)') == False
|
||||
|
||||
# Test de op.div
|
||||
|
||||
|
||||
def test_div_render_tex():
|
||||
assert op.div.__tex__('1', '2') == '\\frac{ 1 }{ 2 }'
|
||||
assert op.div.__tex__('1', '-2') == '\\frac{ 1 }{ -2 }'
|
||||
|
||||
|
||||
def test_div_render_txt():
|
||||
assert op.div.__txt__('1', '2') == '1 / 2'
|
||||
assert op.div.__txt__('1', '-2') == '1 / ( -2 )'
|
||||
|
||||
# Test de op.pw
|
||||
|
||||
|
||||
def test_pw_render_tex():
|
||||
assert op.pw.__tex__('1', '2') == '1^{ 2 }'
|
||||
#assert op.pw.__tex__('1','-2') == '1^{-2}'
|
||||
#assert op.pw.__tex__('-1','2') == '( -1 )^{ 2 }'
|
||||
|
||||
|
||||
def test_pw_render_txt():
|
||||
assert op.pw.__txt__('1', '2') == '1 ^ 2'
|
||||
assert op.pw.__txt__('1', '-2') == '1 ^ ( -2 )'
|
||||
#assert op.pw.__txt__('-1','2') == '( -1 ) ^ 2 '
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
@ -91,7 +91,8 @@ class TestPolynom(unittest.TestCase):
|
||||
self.assertEqual(ans, p.postfix_tokens)
|
||||
|
||||
def test_postfix_neg_coef(self):
|
||||
# TODO: Choix arbitraire (vis à vis des + et des -) il faudra faire en fonction de render |sam. juin 14 09:45:55 CEST 2014
|
||||
# TODO: Choix arbitraire (vis à vis des + et des -) il faudra faire en
|
||||
# fonction de render |sam. juin 14 09:45:55 CEST 2014
|
||||
p = Polynom([-1, -2, -3])
|
||||
#ans = [-1, -2, "x", "*", "+", -3, "x", 2, "^", "*", "+"]
|
||||
ans = [3, 'x', 2, '^', '*', '-', 2, 'x', '*', '-', 1, '-']
|
||||
@ -171,19 +172,11 @@ class TestPolynom(unittest.TestCase):
|
||||
self.assertEqual(str(r), ans)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
@ -7,7 +7,6 @@ import unittest
|
||||
from pymath.calculus.polynomDeg2 import Polynom_deg2
|
||||
|
||||
|
||||
|
||||
class TestPolynomDeg2(unittest.TestCase):
|
||||
"""Testing functions from pymath.calculus.polynomDeg2"""
|
||||
|
||||
@ -18,14 +17,7 @@ if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
|
||||
from pymath.calculus.random_expression import RdExpression
|
||||
|
||||
|
||||
@ -17,6 +16,7 @@ def test_only_form():
|
||||
assert set(rdExp._gene_varia.keys()) == {'a'}
|
||||
assert set(rdExp._gene_2replaced.keys()) == {'a'}
|
||||
|
||||
|
||||
def test_form_with_underscores():
|
||||
form = "_ + 2*_"
|
||||
rdExp = RdExpression(form)
|
||||
@ -28,6 +28,7 @@ def test_form_with_underscores():
|
||||
assert set(rdExp._gene_varia.keys()) == {'A', 'B'}
|
||||
assert set(rdExp._gene_2replaced.keys()) == {'A', 'B'}
|
||||
|
||||
|
||||
def test_only_form_calc():
|
||||
form = "{a+b} + 2"
|
||||
rdExp = RdExpression(form)
|
||||
@ -39,6 +40,7 @@ def test_only_form_calc():
|
||||
assert set(rdExp._gene_varia.keys()), {'a' == 'b'}
|
||||
assert set(rdExp._gene_2replaced.keys()) == {'a+b'}
|
||||
|
||||
|
||||
def test_only_form_cond():
|
||||
form = "{a} + 2"
|
||||
cond = ["{a} == 3"]
|
||||
@ -53,6 +55,7 @@ def test_only_form_cond():
|
||||
|
||||
assert rdExp._gene_varia['a'] == 3
|
||||
|
||||
|
||||
def test_only_form_conds():
|
||||
form = "{a} + 2"
|
||||
cond = ["{a} in list(range(5))", "{a} % 2 == 1"]
|
||||
@ -68,6 +71,7 @@ def test_only_form_conds():
|
||||
assert rdExp._gene_varia['a'] in list(range(5))
|
||||
assert rdExp._gene_varia['a'] % 2 == 1
|
||||
|
||||
|
||||
def test_only_form_calc_cond():
|
||||
form = "{a*3} * {b}"
|
||||
cond = ["{a} == 3"]
|
||||
@ -82,6 +86,7 @@ def test_only_form_calc_cond():
|
||||
|
||||
assert rdExp._gene_varia['a'] == 3
|
||||
|
||||
|
||||
def test_only_form_calc_cond_calc():
|
||||
form = "{a*3} * {b}"
|
||||
cond = ["{a+b} == 3"]
|
||||
@ -97,9 +102,7 @@ def test_only_form_calc_cond_calc():
|
||||
assert (rdExp._gene_varia['a'] + rdExp._gene_varia['b']) == 3
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
@ -21,10 +21,12 @@ def mass_poly_test(operation, rg= 5):
|
||||
:returns: @todo
|
||||
"""
|
||||
coefs_p = [[(i - 2), (j - 2)] for i, j in permutations(range(rg), 2)]
|
||||
coefs_q = [[2*(i-2),2*(j-2)] for i,j in permutations(range(rg),2)]
|
||||
coefs_q = [[2 * (i - 2), 2 * (j - 2)]
|
||||
for i, j in permutations(range(rg), 2)]
|
||||
l_p = [Polynom(i) for i in coefs_p]
|
||||
l_q = [Polynom(i) for i in coefs_q]
|
||||
return [Expression([l_p[i],l_q[j],op.get_op(operation)]) for i,j in permutations(range(len(coefs_p)),2)]
|
||||
return [Expression([l_p[i], l_q[j], op.get_op(operation)])
|
||||
for i, j in permutations(range(len(coefs_p)), 2)]
|
||||
|
||||
|
||||
class TestTexRender(unittest.TestCase):
|
||||
@ -139,7 +141,9 @@ class TestTexRender(unittest.TestCase):
|
||||
|
||||
def test_mult_fraction(self):
|
||||
exps = [[2, Fraction(1, 2), op.mul], [Fraction(1, 2), 3, op.mul]]
|
||||
wanted_render = [ "2 \\times \\frac{ 1 }{ 2 }", "\\frac{ 1 }{ 2 } \\times 3"]
|
||||
wanted_render = [
|
||||
"2 \\times \\frac{ 1 }{ 2 }",
|
||||
"\\frac{ 1 }{ 2 } \\times 3"]
|
||||
for (i, e) in enumerate(exps):
|
||||
rend = tex(e)
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
@ -158,19 +162,19 @@ class TestTexRender(unittest.TestCase):
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_parentheses_int(self):
|
||||
exps = [\
|
||||
[ 2, 3, op.add, 4, op.mul],\
|
||||
[ 2, 3, op.mul, 4, op.add],\
|
||||
[ 2, 3, 4, op.mul, op.add],\
|
||||
[ 2, 3, 4, op.add, op.add],\
|
||||
[ 2, 3, 4, op.add, op.sub],\
|
||||
exps = [
|
||||
[2, 3, op.add, 4, op.mul],
|
||||
[2, 3, op.mul, 4, op.add],
|
||||
[2, 3, 4, op.mul, op.add],
|
||||
[2, 3, 4, op.add, op.add],
|
||||
[2, 3, 4, op.add, op.sub],
|
||||
]
|
||||
wanted_render = [\
|
||||
'( 2 + 3 ) \\times 4',\
|
||||
'2 \\times 3 + 4',\
|
||||
'2 + 3 \\times 4',\
|
||||
'2 + 3 + 4',\
|
||||
'2 - ( 3 + 4 )',\
|
||||
wanted_render = [
|
||||
'( 2 + 3 ) \\times 4',
|
||||
'2 \\times 3 + 4',
|
||||
'2 + 3 \\times 4',
|
||||
'2 + 3 + 4',
|
||||
'2 - ( 3 + 4 )',
|
||||
]
|
||||
for (i, e) in enumerate(exps):
|
||||
rend = tex(e)
|
||||
@ -179,19 +183,19 @@ class TestTexRender(unittest.TestCase):
|
||||
def test_parentheses_poly(self):
|
||||
P = Polynom([1, 2, 3])
|
||||
Q = Polynom([4, 5, 6])
|
||||
exps = [\
|
||||
[ 2, P, op.add],\
|
||||
[ 2, P, op.sub],\
|
||||
[ 2, P, P, op.mul, op.sub],\
|
||||
[ Q, P, op.add],\
|
||||
[ Q, P, op.sub],\
|
||||
exps = [
|
||||
[2, P, op.add],
|
||||
[2, P, op.sub],
|
||||
[2, P, P, op.mul, op.sub],
|
||||
[Q, P, op.add],
|
||||
[Q, P, op.sub],
|
||||
]
|
||||
wanted_render = [\
|
||||
'2 + 3 x^{ 2 } + 2 x + 1' ,\
|
||||
'2 - ( 3 x^{ 2 } + 2 x + 1 )' ,\
|
||||
'2 - ( 3 x^{ 2 } + 2 x + 1 ) ( 3 x^{ 2 } + 2 x + 1 )' ,\
|
||||
'6 x^{ 2 } + 5 x + 4 + 3 x^{ 2 } + 2 x + 1' ,\
|
||||
'6 x^{ 2 } + 5 x + 4 - ( 3 x^{ 2 } + 2 x + 1 )' ,\
|
||||
wanted_render = [
|
||||
'2 + 3 x^{ 2 } + 2 x + 1',
|
||||
'2 - ( 3 x^{ 2 } + 2 x + 1 )',
|
||||
'2 - ( 3 x^{ 2 } + 2 x + 1 ) ( 3 x^{ 2 } + 2 x + 1 )',
|
||||
'6 x^{ 2 } + 5 x + 4 + 3 x^{ 2 } + 2 x + 1',
|
||||
'6 x^{ 2 } + 5 x + 4 - ( 3 x^{ 2 } + 2 x + 1 )',
|
||||
]
|
||||
for (i, e) in enumerate(exps):
|
||||
rend = tex(e)
|
||||
@ -201,8 +205,6 @@ class TestTexRender(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
class TesttxtRender(unittest.TestCase):
|
||||
"""Testing functions from pymath.calculus.renders.txt"""
|
||||
|
||||
@ -216,8 +218,8 @@ class TesttxtRender(unittest.TestCase):
|
||||
self.assertEqual(txt([Fraction(1, 2)]), "1 / 2")
|
||||
|
||||
def test_mult_interger(self):
|
||||
exps = [ [2, 3, op.mul], \
|
||||
[2, -3, op.mul], \
|
||||
exps = [[2, 3, op.mul],
|
||||
[2, -3, op.mul],
|
||||
[-2, 3, op.mul]]
|
||||
wanted_render = ["2 * 3", "2 * ( -3 )", "-2 * 3"]
|
||||
for (i, e) in enumerate(exps):
|
||||
@ -225,9 +227,9 @@ class TesttxtRender(unittest.TestCase):
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_letter(self):
|
||||
exps = [ [2, "a", op.mul], \
|
||||
["a", 3, op.mul], \
|
||||
[-2, "a", op.mul], \
|
||||
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],
|
||||
@ -244,7 +246,7 @@ class TesttxtRender(unittest.TestCase):
|
||||
self.assertEqual(rend, wanted_render[i])
|
||||
|
||||
def test_mult_fraction(self):
|
||||
exps = [ [2, Fraction(1,2), op.mul], \
|
||||
exps = [[2, Fraction(1, 2), op.mul],
|
||||
[Fraction(1, 2), 3, op.mul]]
|
||||
wanted_render = ["2 * 1 / 2", "1 / 2 * 3"]
|
||||
for (i, e) in enumerate(exps):
|
||||
@ -254,17 +256,17 @@ class TesttxtRender(unittest.TestCase):
|
||||
def test_parentheses(self):
|
||||
mul = op.get_op("*", 2)
|
||||
add = op.get_op("+", 2)
|
||||
exps = [\
|
||||
[ 2, 3, add, 4, mul],\
|
||||
[ 2, 3, mul, 4, add],\
|
||||
[ 2, 3, 4, mul, add],\
|
||||
[ 2, 3, 4, add, add],\
|
||||
exps = [
|
||||
[2, 3, add, 4, mul],
|
||||
[2, 3, mul, 4, add],
|
||||
[2, 3, 4, mul, add],
|
||||
[2, 3, 4, add, add],
|
||||
]
|
||||
wanted_render = [\
|
||||
'( 2 + 3 ) * 4',\
|
||||
'2 * 3 + 4',\
|
||||
'2 + 3 * 4',\
|
||||
'2 + 3 + 4',\
|
||||
wanted_render = [
|
||||
'( 2 + 3 ) * 4',
|
||||
'2 * 3 + 4',
|
||||
'2 + 3 * 4',
|
||||
'2 + 3 + 4',
|
||||
]
|
||||
for (i, e) in enumerate(exps):
|
||||
rend = txt(e)
|
||||
@ -296,15 +298,7 @@ if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
@ -7,6 +7,7 @@ import unittest
|
||||
from pymath.calculus.str2tokens import str2tokens, str2in_tokens, in2post_fix
|
||||
from pymath.calculus.polynom import Polynom
|
||||
|
||||
|
||||
class TestStr2tokens(unittest.TestCase):
|
||||
"""Testing functions from pymath.calculus.str2tokens"""
|
||||
|
||||
@ -17,7 +18,6 @@ class TestStr2tokens(unittest.TestCase):
|
||||
ans = str2in_tokens("2*3+4")
|
||||
self.assertEqual(ans, [2, "*", 3, "+", 4])
|
||||
|
||||
|
||||
def test_in2post_fix(self):
|
||||
in_tokens = str2in_tokens("2+3*4")
|
||||
ans = in2post_fix(in_tokens)
|
||||
@ -27,8 +27,8 @@ class TestStr2tokens(unittest.TestCase):
|
||||
ans = in2post_fix(in_tokens)
|
||||
self.assertEqual(ans, [2, 3, "*", 4, "+"])
|
||||
|
||||
|
||||
# TODO: Ajouter des tests pour les cas particuliers... |sam. nov. 8 17:39:18 CET 2014
|
||||
# TODO: Ajouter des tests pour les cas particuliers... |sam. nov. 8
|
||||
# 17:39:18 CET 2014
|
||||
def test_str2in_tokens_big_num(self):
|
||||
exp = "123 + 3"
|
||||
tok = str2in_tokens(exp)
|
||||
@ -49,7 +49,6 @@ class TestStr2tokens(unittest.TestCase):
|
||||
post = str2in_tokens(exp)
|
||||
self.assertEqual(post, [2, "*", Polynom([0, 1]), '+', 4])
|
||||
|
||||
|
||||
def test_str2tokens_poly_double_x(self):
|
||||
exp = "xx + 4"
|
||||
post = str2in_tokens(exp)
|
||||
@ -58,7 +57,8 @@ class TestStr2tokens(unittest.TestCase):
|
||||
def test_str2tokens_poly(self):
|
||||
exp = "x(2+1) + 4"
|
||||
post = str2in_tokens(exp)
|
||||
self.assertEqual(post, [Polynom([0, 1]), "*", "(", 2, "+", 1, ')', '+', 4])
|
||||
self.assertEqual(post, [Polynom([0, 1]), "*",
|
||||
"(", 2, "+", 1, ')', '+', 4])
|
||||
|
||||
def test_str2in_tokens_time_lack2(self):
|
||||
exp = "-3(2)"
|
||||
@ -74,7 +74,6 @@ class TestStr2tokens(unittest.TestCase):
|
||||
self.assertRaises(ValueError, str2tokens, exp)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@ -83,4 +82,3 @@ if __name__ == '__main__':
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user