Mapytex/pymath/calculus/test/test_operator.py

99 lines
2.5 KiB
Python
Raw Normal View History

2015-03-10 10:59:35 +00:00
#!/usr/bin/env python
# encoding: utf-8
2016-01-07 16:56:30 +00:00
from pymath.calculus.operator import op
2015-03-10 10:59:35 +00:00
2015-04-03 12:49:55 +00:00
# Test de op.add
def test_add_render_tex():
2016-02-13 03:49:37 +00:00
assert op.add.__tex__('1', '2') == '1 + 2'
assert op.add.__tex__('1', '-2') == '1 - 2'
2015-04-03 12:49:55 +00:00
def test_add_render_txt():
2016-02-13 03:49:37 +00:00
assert op.add.__txt__('1', '2') == '1 + 2'
assert op.add.__txt__('1', '-2') == '1 - 2'
2015-04-03 12:49:55 +00:00
# Test de op.sub
2016-02-13 03:49:37 +00:00
2015-04-03 12:49:55 +00:00
def test_sub_render_tex():
2016-02-13 03:49:37 +00:00
assert op.sub.__tex__('1', '2') == '1 - 2'
assert op.sub.__tex__('1', '-2') == '1 - ( -2 )'
2015-04-03 12:49:55 +00:00
def test_sub_render_txt():
2016-02-13 03:49:37 +00:00
assert op.sub.__txt__('1', '2') == '1 - 2'
assert op.sub.__txt__('1', '-2') == '1 - ( -2 )'
2015-04-03 12:49:55 +00:00
# Test de op.sub1
2016-02-13 03:49:37 +00:00
2015-04-03 12:49:55 +00:00
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
2016-02-13 03:49:37 +00:00
2015-04-03 12:49:55 +00:00
def test_mul_render_tex():
2016-02-13 03:49:37 +00:00
assert op.mul.__tex__('1', '2') == '1 \\times 2'
assert op.mul.__tex__('1', '-2') == '1 \\times ( -2 )'
2015-04-03 12:49:55 +00:00
def test_mul_render_txt():
2016-02-13 03:49:37 +00:00
assert op.mul.__txt__('1', '2') == '1 * 2'
assert op.mul.__txt__('1', '-2') == '1 * ( -2 )'
2015-04-03 12:49:55 +00:00
2015-03-10 10:59:35 +00:00
def test_mul_is_visible():
2016-02-13 03:49:37 +00:00
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
2015-03-10 10:59:35 +00:00
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
2015-04-03 12:49:55 +00:00
# Test de op.div
2016-02-13 03:49:37 +00:00
2015-04-03 12:49:55 +00:00
def test_div_render_tex():
2016-02-13 03:49:37 +00:00
assert op.div.__tex__('1', '2') == '\\frac{ 1 }{ 2 }'
assert op.div.__tex__('1', '-2') == '\\frac{ 1 }{ -2 }'
2015-04-03 12:49:55 +00:00
def test_div_render_txt():
2016-02-13 03:49:37 +00:00
assert op.div.__txt__('1', '2') == '1 / 2'
assert op.div.__txt__('1', '-2') == '1 / ( -2 )'
2015-04-03 12:49:55 +00:00
# Test de op.pw
2016-02-13 03:49:37 +00:00
2015-04-03 12:49:55 +00:00
def test_pw_render_tex():
2016-02-13 03:49:37 +00:00
assert op.pw.__tex__('1', '2') == '1^{ 2 }'
2015-04-03 13:56:36 +00:00
#assert op.pw.__tex__('1','-2') == '1^{-2}'
#assert op.pw.__tex__('-1','2') == '( -1 )^{ 2 }'
2015-03-10 10:59:35 +00:00
2016-02-13 03:49:37 +00:00
2015-04-03 12:49:55 +00:00
def test_pw_render_txt():
2016-02-13 03:49:37 +00:00
assert op.pw.__txt__('1', '2') == '1 ^ 2'
assert op.pw.__txt__('1', '-2') == '1 ^ ( -2 )'
2015-04-03 13:56:36 +00:00
#assert op.pw.__txt__('-1','2') == '( -1 ) ^ 2 '
2015-03-10 10:59:35 +00:00
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
2016-02-13 03:29:26 +00:00
# cursor: 16 del