From 1e3e0418df069f5c2e05f22e5c5e975d7f7f70ad Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sat, 27 Feb 2016 09:07:54 +0300 Subject: [PATCH] move test into class those tests are passed --- pymath/calculus/operator/add.py | 20 ++++ pymath/calculus/operator/div.py | 16 ++- pymath/calculus/operator/mul.py | 43 ++++++-- pymath/calculus/operator/operator.py | 2 +- pymath/calculus/operator/pw.py | 10 +- pymath/calculus/operator/sub.py | 14 ++- pymath/calculus/operator/sub1.py | 10 +- pymath/calculus/operator/test/test_add.py | 21 ---- .../calculus/operator/test/test_operator.py | 98 ------------------- 9 files changed, 92 insertions(+), 142 deletions(-) delete mode 100644 pymath/calculus/operator/test/test_add.py delete mode 100644 pymath/calculus/operator/test/test_operator.py diff --git a/pymath/calculus/operator/add.py b/pymath/calculus/operator/add.py index d4110ac..ba861c8 100644 --- a/pymath/calculus/operator/add.py +++ b/pymath/calculus/operator/add.py @@ -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" : "+", \ diff --git a/pymath/calculus/operator/div.py b/pymath/calculus/operator/div.py index 51d67c0..9b661c9 100644 --- a/pymath/calculus/operator/div.py +++ b/pymath/calculus/operator/div.py @@ -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",\ diff --git a/pymath/calculus/operator/mul.py b/pymath/calculus/operator/mul.py index 7ac8fb0..d9bd6c1 100644 --- a/pymath/calculus/operator/mul.py +++ b/pymath/calculus/operator/mul.py @@ -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: diff --git a/pymath/calculus/operator/operator.py b/pymath/calculus/operator/operator.py index 0efd1d9..f1044f8 100644 --- a/pymath/calculus/operator/operator.py +++ b/pymath/calculus/operator/operator.py @@ -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) diff --git a/pymath/calculus/operator/pw.py b/pymath/calculus/operator/pw.py index b98103a..8b8cbaa 100644 --- a/pymath/calculus/operator/pw.py +++ b/pymath/calculus/operator/pw.py @@ -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 = { diff --git a/pymath/calculus/operator/sub.py b/pymath/calculus/operator/sub.py index 43d46ef..4dd7c7f 100644 --- a/pymath/calculus/operator/sub.py +++ b/pymath/calculus/operator/sub.py @@ -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 = { diff --git a/pymath/calculus/operator/sub1.py b/pymath/calculus/operator/sub1.py index dcd8300..49ccd2e 100644 --- a/pymath/calculus/operator/sub1.py +++ b/pymath/calculus/operator/sub1.py @@ -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 = { diff --git a/pymath/calculus/operator/test/test_add.py b/pymath/calculus/operator/test/test_add.py deleted file mode 100644 index 4d62688..0000000 --- a/pymath/calculus/operator/test/test_add.py +++ /dev/null @@ -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 diff --git a/pymath/calculus/operator/test/test_operator.py b/pymath/calculus/operator/test/test_operator.py deleted file mode 100644 index 0fe305f..0000000 --- a/pymath/calculus/operator/test/test_operator.py +++ /dev/null @@ -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