new clean postfix_tokens method for Abstact_Poly (still a bug with mass

test render)
This commit is contained in:
Benjamin Bertrand
2016-03-11 18:16:19 +03:00
parent 9529c32b50
commit a0b014dd08
3 changed files with 1121 additions and 1100 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -48,26 +48,6 @@ class TestPolynom(unittest.TestCase):
p = Polynom([1, 2])
self.assertEqual(p("h+1"), Polynom([3, 2], "h"))
# def test_print(self):
# p = Polynom([1,2,3])
# ans = "1 + 2 x + 3 x^2"
# self.assertEqual(ans, str(p))
# def test_print_monom(self):
# p = Polynom([0,2])
# ans = "2 x"
# self.assertEqual(ans, str(p))
# def test_print_0_coef(self):
# p = Polynom([0,1,3])
# ans = "x + 3 x^2"
# self.assertEqual(ans, str(p))
# def test_print_multi_coef(self):
# p = Polynom([1,[2, -2],3])
# ans = "1 + 2 x - 2 x + 3 x^2"
# self.assertEqual(ans, str(p))
def test_postfix(self):
p = Polynom([1, 2, 3])
ans = [3, 'x', 2, op.pw, op.mul, 2, 'x', op.mul, op.add, 1, op.add]
@@ -90,7 +70,7 @@ class TestPolynom(unittest.TestCase):
def test_postfix_neg_coef(self):
p = Polynom([-1, -2, -3])
ans = [3, 'x', 2, op.pw, op.mul, op.sub1, 2, 'x', op.mul, op.sub, 1, op.sub]
ans = [-3, 'x', 2, op.pw, op.mul, -2, 'x', op.mul, op.add, -1, op.add]
self.assertEqual(ans, p.postfix_tokens)
def test_postfix_multi_coef(self):
@@ -98,11 +78,46 @@ class TestPolynom(unittest.TestCase):
ans = [4, 'x', 2, op.pw, op.mul, 2, 'x', op.mul, op.add, 3, 'x', op.mul, op.add, 1, op.add]
self.assertEqual(ans, p.postfix_tokens)
def test_postfix_arithm_coef(self):
def test_postfix_exp_coef(self):
p = Polynom([1, Expression([2, 3, "+"]), 4])
ans = [4, 'x', 2, op.pw, op.mul, 2, 3, op.add, 'x', op.mul, op.add, 1, op.add]
self.assertEqual(ans, p.postfix_tokens)
def test_str(self):
p = Polynom([1, 2, 3])
ans = '3 x^{ 2 } + 2 x + 1'
self.assertEqual(ans, str(p))
def test_str_monom(self):
p = Polynom([0, 2])
ans = '2 x'
self.assertEqual(ans, str(p))
def test_str_0_coef(self):
p = Polynom([0, 2, 0, 4])
ans = '4 x^{ 3 } + 2 x'
self.assertEqual(ans, str(p))
def test_str_1_coef(self):
p = Polynom([0, 1, 1])
ans = 'x^{ 2 } + x'
self.assertEqual(ans, str(p))
def test_str_neg_coef(self):
p = Polynom([-1, -2, -3])
ans = '-3 x^{ 2 } - 2 x - 1'
self.assertEqual(ans, str(p))
def test_str_multi_coef(self):
p = Polynom([1, [2, 3], 4])
ans = '4 x^{ 2 } + 2 x + 3 x + 1'
self.assertEqual(ans, str(p))
def test_str_exp_coef(self):
p = Polynom([1, Expression([2, 3, "+"]), 4])
ans = '4 x^{ 2 } + ( 2 + 3 ) x + 1'
self.assertEqual(ans, str(p))
def test_reduce_nilpo(self):
p = Polynom([1, 2, 3])
self.assertEqual(p, p.reduce())