예제 #1
0
 def test_add_brackets(self):
     tests = {
         'x*x': '(x)(x)',
         '2x^2+6x*4x+3': '2x^2+(6x)(4x)+3',
         '2x^2+6x(4x)+3': '2x^2+(6x)(4x)+3',
         'x*(x+3)(2x^2-4)+2(x^2-3)': '(x)(x+3)(2x^2-4)+(2)(x^2-3)',
         'x*(x+3)(2x^2-4)+2x(x^2-3)3': '(x)(x+3)(2x^2-4)+(2x)(x^2-3)(3)',
     }
     for test in sorted(tests):
         answer = main.add_brackets(test)
         self.assertEqual(answer, tests[test])
예제 #2
0
    def test_add_mul(self):
        tests = {
            'x': 'x',
            '2x^2': '2x^2',
            '2x(x)': '(2x)*(x)',
            '2x(x+5)': '(2x)*(x+5)',
            '2x(2x^2+5x-8)': '(2x)*(2x^2+5x-8)',
            '(2x^2+2x)(x+5)': '(2x^2+2x)*(x+5)',
            '(x+5)(2x^2+x(3x^3+5))': '(x+5)*(2x^2+(x)*(3x^3+5))',
        }

        for test in sorted(tests):
            answer = main.add_mul_between_brackets(main.add_brackets(test))

            self.assertEqual(answer, tests[test])