create massive test for render

This commit is contained in:
lafrite 2015-06-21 16:59:16 +02:00
parent 8f59dd1e73
commit 2e8cd9dd48
3 changed files with 57 additions and 16 deletions

4
test/mass_test.py Normal file

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,23 @@ from pymath.render import tex, txt,p2i
from pymath.fraction import Fraction
from pymath.polynom import Polynom
from pymath.operator import op
from pymath.expression import Expression
from itertools import permutations
def mass_poly_test(operation, rg= 5):
""" @todo
:op: the operation
:rg: number of potential values for coefs
: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)]
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)]
class TestTexRender(unittest.TestCase):
@ -40,6 +56,24 @@ class TestTexRender(unittest.TestCase):
rend = tex(e)
self.assertEqual(rend, wanted_render[i])
def test_mass_add(self):
permu = mass_poly_test("+",5)
from .mass_test import POLY_ADD_VALID_RESULTS
for (i,v) in enumerate(permu):
self.assertEqual(tex(v), POLY_ADD_VALID_RESULTS[i])
def test_mass_sub(self):
permu = mass_poly_test("-",5)
from .mass_test import POLY_SUB_VALID_RESULTS
for (i,v) in enumerate(permu):
self.assertEqual(tex(v), POLY_SUB_VALID_RESULTS[i])
def test_mass_mul(self):
permu = mass_poly_test("*",5)
from .mass_test import TEX_POLY_MUL_VALID_RESULTS
for (i,v) in enumerate(permu):
self.assertEqual(tex(v), TEX_POLY_MUL_VALID_RESULTS[i])
def test_add_letter(self):
exps = [[2, "a", op.add ],
["a", 3, op.add ],
@ -239,6 +273,24 @@ class TesttxtRender(unittest.TestCase):
def test_slash(self):
pass
def test_mass_add(self):
permu = mass_poly_test("+",5)
from .mass_test import POLY_ADD_VALID_RESULTS
for (i,v) in enumerate(permu):
self.assertEqual(txt(v), POLY_ADD_VALID_RESULTS[i])
def test_mass_sub(self):
permu = mass_poly_test("-",5)
from .mass_test import POLY_SUB_VALID_RESULTS
for (i,v) in enumerate(permu):
self.assertEqual(txt(v), POLY_SUB_VALID_RESULTS[i])
def test_mass_mul(self):
permu = mass_poly_test("*",5)
from .mass_test import TXT_POLY_MUL_VALID_RESULTS
for (i,v) in enumerate(permu):
self.assertEqual(txt(v), TXT_POLY_MUL_VALID_RESULTS[i])
if __name__ == '__main__':
unittest.main()
@ -250,6 +302,7 @@ if __name__ == '__main__':
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:

View File

@ -1,16 +0,0 @@
Faire tous les cas de figures
=============================
Tester toutes les multiplications possibles
-------------------------------------------
.. code-block:: python
>>> from itertools import permutations
>>> coefs_p = [[(i-2),(j-2)] for i,j in permutations(range(5),2)]
>>> coefs_q = [[2*(i-2),2*(j-2)] for i,j in permutations(range(5),2)]
>>> l_p = [Polynom(i) for i in coefs_p]
>>> l_q = [Polynom(i) for i in coefs_q]
>>> operations = [Expression([l_p[i],l_q[j],op.mul]) for i,j in permutations(range(len(coefs_p)),2)]
>>> for i in operations:
... print(i)