move test into class those tests are passed

This commit is contained in:
Benjamin Bertrand 2016-02-27 09:07:54 +03:00
parent 8ed382bbe2
commit 1e3e0418df
9 changed files with 92 additions and 142 deletions

View File

@ -4,6 +4,26 @@
from .operator import Operator, save_mainOp from .operator import Operator, save_mainOp
class Add(Operator): class Add(Operator):
r""" The operator +
>>> add = Add()
>>> add
+
>>> add(1, 2)
3
>>> add.__tex__('1','2')
'1 + 2'
>>> add.__tex__('-1','2')
'-1 + 2'
>>> add.__tex__('1','-2')
'1 - 2'
>>> add.__txt__('1','2')
'1 + 2'
>>> add.__txt__('-1','2')
'-1 + 2'
>>> add.__txt__('1','-2')
'1 - 2'
"""
_CARACT = { _CARACT = {
"operator" : "+", \ "operator" : "+", \

View File

@ -4,21 +4,27 @@
from .operator import Operator, save_mainOp from .operator import Operator, save_mainOp
class Div(Operator): class Div(Operator):
r""" The operator /
""" The operator / >>> div = Div()
>>> div = op.div
>>> div >>> div
'/' /
>>> div(1, 2) >>> div(1, 2)
< Fraction 1 / 2> < Fraction 1 / 2>
>>> div.__tex__('1','2') >>> div.__tex__('1','2')
'\\frac{ 1 }{ 2 }' '\\frac{ 1 }{ 2 }'
>>> div.__tex__('1','2') >>> div.__tex__('-1','2')
'\\frac{ -1 }{ 2 }' '\\frac{ -1 }{ 2 }'
>>> div.__tex__('1','-2')
'\\frac{ 1 }{ -2 }'
>>> div.__txt__('1','2') >>> div.__txt__('1','2')
'1 / 2' '1 / 2'
>>> div.__txt__('-1','2')
'-1 / 2'
>>> div.__txt__('1','-2')
'1 / ( -2 )'
""" """
_CARACT = { _CARACT = {
"operator" : "/", \ "operator" : "/", \
"name" : "div",\ "name" : "div",\

View File

@ -5,26 +5,28 @@
from .operator import Operator, save_mainOp from .operator import Operator, save_mainOp
class Mul(Operator): class Mul(Operator):
r""" The operator *
""" The operator * >>> mul = Mul()
>>> mul = op.mul
>>> mul >>> mul
'*' *
>>> mul(1, 2) >>> mul(1, 2)
2 2
>>> mul.__tex__('1','2') >>> mul.__tex__('1','2')
'1 \\times 2' '1 \\times 2'
>>> mul.__tex__('2','a') >>> mul.__tex__('2','a')
'2 a' '2 a'
>>> mul.__tex__('1','-2')
'1 \\times ( -2 )'
>>> mul.__txt__('1','2') >>> mul.__txt__('1','2')
'1 * 2' '1 * 2'
>>> mul.__txt__('2','a') >>> mul.__txt__('2','a')
'2 a' '2 a'
>>> mul.__txt__('a','2') >>> mul.__txt__('a','2')
'a * 2' 'a * 2'
>>> mul.__tex__('1','-2') >>> mul.__txt__('1','-2')
'1 \\times (-2)' '1 * ( -2 )'
""" """
_CARACT = { _CARACT = {
@ -50,6 +52,35 @@ class Mul(Operator):
:param op1: left operande :param op1: left operande
:param op2: rigth operande :param op2: rigth operande
>>> m = Mul()
>>> m.is_visible(2, 3)
True
>>> m.is_visible(2, -3)
True
>>> m.is_visible(-2, 3)
True
>>> m.is_visible('a', 2)
True
>>> m.is_visible('(2a + 1)', 2)
True
>>> m.is_visible(2, '(-2)')
True
>>> m.is_visible(2, '2a')
True
>>> m.is_visible(2, '(-2a)')
True
>>> m.is_visible(2, '(-2abc)')
True
>>> m.is_visible(2, 'a')
False
>>> m.is_visible(2, '(2a + 1)')
False
>>> m.is_visible('(3x - 1)', '(2a + 1)')
False
>>> m.is_visible(2, '(-2x + 1)(3x + 2)')
False
""" """
# TODO: À finir!!! |lun. mars 9 00:03:40 CET 2015 # TODO: À finir!!! |lun. mars 9 00:03:40 CET 2015
if type(op2) == int: if type(op2) == int:

View File

@ -56,7 +56,7 @@ class Operator():
return ans return ans
def __repr__(self): def __repr__(self):
return self.operator return str(self.operator)
def __str__(self): def __str__(self):
return str(self.operator) return str(self.operator)

View File

@ -9,17 +9,23 @@ class Pw(Operator):
""" The operator ^ """ The operator ^
>>> pw = op.pw >>> pw = Pw()
>>> pw >>> pw
'^' ^
>>> pw(2, 3) >>> pw(2, 3)
8 8
>>> pw.__tex__('2','3') >>> pw.__tex__('2','3')
'2^{ 3 }' '2^{ 3 }'
>>> pw.__tex__('2','-3')
'2^{ -3 }'
>>> pw.__tex__('-2','3')
'( -2 )^{ -3 }'
>>> pw.__txt__('2','3') >>> pw.__txt__('2','3')
'2 ^ 3' '2 ^ 3'
>>> pw.__txt__('-2','3') >>> pw.__txt__('-2','3')
'( -2 ) ^ 3' '( -2 ) ^ 3'
>>> pw.__txt__('2','-3')
'2 ^ ( -3 )'
""" """
_CARACT = { _CARACT = {

View File

@ -9,19 +9,23 @@ class Sub(Operator):
""" The operator - """ The operator -
>>> sub = op.sub >>> sub = Sub()
>>> sub >>> sub
'-' -
>>> sub(1, 2) >>> sub(1, 2)
-1 -1
>>> sub.__tex__('1','2') >>> sub.__tex__('1','2')
'1 - 2' '1 - 2'
>>> sub.__txt__('1','2')
'1 - 2'
>>> sub.__tex__('1','-2') >>> sub.__tex__('1','-2')
'1 - ( -2 )' '1 - ( -2 )'
>>> sub.__tex__('-1','2') >>> sub.__tex__('-1','2')
'-1 - 2' '-1 - 2'
>>> sub.__txt__('1','2')
'1 - 2'
>>> sub.__txt__('1','-2')
'1 - ( -2 )'
>>> sub.__txt__('-1','2')
'-1 - 2'
""" """
_CARACT = { _CARACT = {
"operator" : "-", \ "operator" : "-", \

View File

@ -9,16 +9,18 @@ class Sub1(Operator):
""" The operator - """ The operator -
>>> sub1 = op.sub1 >>> sub1 = Sub1()
>>> sub1 >>> sub1
'-' -
>>> sub1(1) >>> sub1(1)
-1 -1
>>> sub1.__tex__('1') >>> sub1.__tex__('1')
'- 1' '- 1'
>>> sub1.__tex__('-1')
'- ( -1 )'
>>> sub1.__txt__('1') >>> sub1.__txt__('1')
'- 1' '- 1'
>>> sub1.__tex__('-1') >>> sub1.__txt__('-1')
'- ( -1 )' '- ( -1 )'
""" """

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python
# encoding: utf-8
from pymath.calculus.operator.add import Add
def test_add_render_tex():
assert Add().__tex__('1', '2') == '1 + 2'
assert Add().__tex__('1', '-2') == '1 - 2'
def test_add_render_txt():
assert Add().__txt__('1', '2') == '1 + 2'
assert Add().__txt__('1', '-2') == '1 - 2'
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

View File

@ -1,98 +0,0 @@
#!/usr/bin/env python
# encoding: utf-8
from pymath.calculus.operator import op
# Test de op.add
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 )'
assert op.sub1.__txt__('1') == '- 1'
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)
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
assert op.mul.is_visible('(3x - 1)', '(2a + 1)') == False
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