From 26e12370b84c15118c3347f05e36d2bd402ba2f9 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sat, 27 Feb 2016 12:01:26 +0300 Subject: [PATCH] pass expression and str2tokens tests --- pymath/calculus/test/test_expression.py | 11 ++++++----- pymath/calculus/test/test_str2tokens.py | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pymath/calculus/test/test_expression.py b/pymath/calculus/test/test_expression.py index 90a7f4f..cc34e0f 100644 --- a/pymath/calculus/test/test_expression.py +++ b/pymath/calculus/test/test_expression.py @@ -8,11 +8,12 @@ from pymath.calculus.expression import Expression from pymath.calculus.fraction import Fraction from pymath.calculus.generic import first_elem from pymath.calculus.render import txt, tex +from pymath.calculus.operator import op def test_init_from_str(): exp = Expression("2 + 3") - assert exp.postfix_tokens == [2, 3, "+"] + assert exp.postfix_tokens == [2, 3, op.add] def test_init_from_exp(): @@ -21,7 +22,7 @@ def test_init_from_exp(): def test_init_list(): exp = Expression([2, 3, "+"]) - assert exp.postfix_tokens == [2, 3, "+"] + assert exp.postfix_tokens == [2, 3, op.add] def test_init_one_element_int_from_str(): @@ -66,20 +67,20 @@ def test_add_exp(): e = Expression("12- 4") f = Expression("4 + 1") g = e + f - assert g.postfix_tokens == [12, 4, '-', 4, 1, "+", "+"] + assert g.postfix_tokens == [12, 4, op.sub, 4, 1, op.add, op.add] def test_mul_exp(): e = Expression("12- 4") f = Expression("4 + 1") g = e * f - assert g.postfix_tokens == [12, 4, '-', 4, 1, "+", "*"] + assert g.postfix_tokens == [12, 4, op.sub, 4, 1, op.add, op.mul] def test_neg_exp(): e = Expression("12- 4") g = -e - assert g.postfix_tokens == [12, 4, '-', '-'] + assert g.postfix_tokens == [12, 4, op.sub, op.sub1] # ----------------------------- diff --git a/pymath/calculus/test/test_str2tokens.py b/pymath/calculus/test/test_str2tokens.py index d880ff0..213bd2f 100644 --- a/pymath/calculus/test/test_str2tokens.py +++ b/pymath/calculus/test/test_str2tokens.py @@ -6,12 +6,13 @@ import unittest from pymath.calculus.str2tokens import str2tokens, str2in_tokens, in2post_fix from pymath.calculus.polynom import Polynom +from pymath.calculus.operator import op class TestStr2tokens(unittest.TestCase): """Testing functions from pymath.calculus.str2tokens""" - def test_str2intokens(self): + def test_str2in_tokens(self): ans = str2in_tokens("2+3*4") self.assertEqual(ans, [2, "+", 3, "*", 4]) @@ -25,11 +26,11 @@ class TestStr2tokens(unittest.TestCase): def test_in2post_fix(self): in_tokens = str2in_tokens("2+3*4") ans = in2post_fix(in_tokens) - self.assertEqual(ans, [2, 3, 4, "*", "+"]) + self.assertEqual(ans, [2, 3, 4, op.mul, op.add]) in_tokens = str2in_tokens("2*3+4") ans = in2post_fix(in_tokens) - self.assertEqual(ans, [2, 3, "*", 4, "+"]) + self.assertEqual(ans, [2, 3, op.mul, 4, op.add]) def test_str2in_tokens_big_num(self): exp = "123 + 3"