move test into class those tests are passed
This commit is contained in:
parent
8ed382bbe2
commit
1e3e0418df
@ -4,6 +4,26 @@
|
||||
from .operator import Operator, save_mainOp
|
||||
|
||||
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 = {
|
||||
"operator" : "+", \
|
||||
|
@ -4,21 +4,27 @@
|
||||
from .operator import Operator, save_mainOp
|
||||
|
||||
class Div(Operator):
|
||||
r""" The operator /
|
||||
|
||||
""" The operator /
|
||||
|
||||
>>> div = op.div
|
||||
>>> div = Div()
|
||||
>>> div
|
||||
'/'
|
||||
/
|
||||
>>> div(1, 2)
|
||||
< Fraction 1 / 2>
|
||||
>>> div.__tex__('1','2')
|
||||
'\\frac{ 1 }{ 2 }'
|
||||
>>> div.__tex__('1','2')
|
||||
>>> div.__tex__('-1','2')
|
||||
'\\frac{ -1 }{ 2 }'
|
||||
>>> div.__tex__('1','-2')
|
||||
'\\frac{ 1 }{ -2 }'
|
||||
>>> div.__txt__('1','2')
|
||||
'1 / 2'
|
||||
>>> div.__txt__('-1','2')
|
||||
'-1 / 2'
|
||||
>>> div.__txt__('1','-2')
|
||||
'1 / ( -2 )'
|
||||
"""
|
||||
|
||||
_CARACT = {
|
||||
"operator" : "/", \
|
||||
"name" : "div",\
|
||||
|
@ -5,26 +5,28 @@
|
||||
from .operator import Operator, save_mainOp
|
||||
|
||||
class Mul(Operator):
|
||||
r""" The operator *
|
||||
|
||||
""" The operator *
|
||||
|
||||
>>> mul = op.mul
|
||||
>>> mul = Mul()
|
||||
>>> mul
|
||||
'*'
|
||||
*
|
||||
>>> mul(1, 2)
|
||||
2
|
||||
>>> mul.__tex__('1','2')
|
||||
'1 \\times 2'
|
||||
>>> mul.__tex__('2','a')
|
||||
'2 a'
|
||||
>>> mul.__tex__('1','-2')
|
||||
'1 \\times ( -2 )'
|
||||
|
||||
>>> 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)'
|
||||
>>> mul.__txt__('1','-2')
|
||||
'1 * ( -2 )'
|
||||
"""
|
||||
|
||||
_CARACT = {
|
||||
@ -50,6 +52,35 @@ class Mul(Operator):
|
||||
:param op1: left 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
|
||||
if type(op2) == int:
|
||||
|
@ -56,7 +56,7 @@ class Operator():
|
||||
return ans
|
||||
|
||||
def __repr__(self):
|
||||
return self.operator
|
||||
return str(self.operator)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.operator)
|
||||
|
@ -9,17 +9,23 @@ class Pw(Operator):
|
||||
|
||||
""" The operator ^
|
||||
|
||||
>>> pw = op.pw
|
||||
>>> pw = Pw()
|
||||
>>> pw
|
||||
'^'
|
||||
^
|
||||
>>> pw(2, 3)
|
||||
8
|
||||
>>> pw.__tex__('2','3')
|
||||
'2^{ 3 }'
|
||||
>>> pw.__tex__('2','-3')
|
||||
'2^{ -3 }'
|
||||
>>> pw.__tex__('-2','3')
|
||||
'( -2 )^{ -3 }'
|
||||
>>> pw.__txt__('2','3')
|
||||
'2 ^ 3'
|
||||
>>> pw.__txt__('-2','3')
|
||||
'( -2 ) ^ 3'
|
||||
>>> pw.__txt__('2','-3')
|
||||
'2 ^ ( -3 )'
|
||||
"""
|
||||
|
||||
_CARACT = {
|
||||
|
@ -9,18 +9,22 @@ class Sub(Operator):
|
||||
|
||||
""" The operator -
|
||||
|
||||
>>> sub = op.sub
|
||||
>>> sub = Sub()
|
||||
>>> sub
|
||||
'-'
|
||||
-
|
||||
>>> sub(1, 2)
|
||||
-1
|
||||
>>> sub.__tex__('1','2')
|
||||
'1 - 2'
|
||||
>>> sub.__tex__('1','-2')
|
||||
'1 - ( -2 )'
|
||||
>>> sub.__tex__('-1','2')
|
||||
'-1 - 2'
|
||||
>>> sub.__txt__('1','2')
|
||||
'1 - 2'
|
||||
>>> sub.__tex__('1','-2')
|
||||
'1 - (-2)'
|
||||
>>> sub.__tex__('-1','2')
|
||||
>>> sub.__txt__('1','-2')
|
||||
'1 - ( -2 )'
|
||||
>>> sub.__txt__('-1','2')
|
||||
'-1 - 2'
|
||||
"""
|
||||
_CARACT = {
|
||||
|
@ -9,17 +9,19 @@ class Sub1(Operator):
|
||||
|
||||
""" The operator -
|
||||
|
||||
>>> sub1 = op.sub1
|
||||
>>> sub1 = Sub1()
|
||||
>>> sub1
|
||||
'-'
|
||||
-
|
||||
>>> sub1(1)
|
||||
-1
|
||||
>>> sub1.__tex__('1')
|
||||
'- 1'
|
||||
>>> sub1.__tex__('-1')
|
||||
'- ( -1 )'
|
||||
>>> sub1.__txt__('1')
|
||||
'- 1'
|
||||
>>> sub1.__tex__('-1')
|
||||
'- (-1)'
|
||||
>>> sub1.__txt__('-1')
|
||||
'- ( -1 )'
|
||||
"""
|
||||
|
||||
_CARACT = {
|
||||
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user