1
exercism fetch python bracket-push

bracket_push_test.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import unittest

from bracket_push import check_brackets


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class BracketPushTests(unittest.TestCase):
    def test_paired_square_brackets(self):
        self.assertEqual(check_brackets("[]"), True)

    def test_empty_string(self):
        self.assertEqual(check_brackets(""), True)

    def test_unpaired_brackets(self):
        self.assertEqual(check_brackets("[["), False)

    def test_wrong_ordered_brackets(self):
        self.assertEqual(check_brackets("}{"), False)

    def test_wrong_closing_bracket(self):
        self.assertEqual(check_brackets("{]"), False)

    def test_paired_with_whitespace(self):
        self.assertEqual(check_brackets("{ }"), True)

    def test_simple_nested_brackets(self):
        self.assertEqual(check_brackets("{[]}"), True)

    def test_several_paired_brackets(self):
        self.assertEqual(check_brackets("{}[]"), True)

    def test_paired_and_nested_brackets(self):
        self.assertEqual(check_brackets("([{}({}[])])"), True)

    def test_unopened_closing_brackets(self):
        self.assertEqual(check_brackets("{[)][]}"), False)

    def test_unpaired_and_nested_brackets(self):
        self.assertEqual(check_brackets("([{])"), False)

    def test_paired_and_wrong_nested_brackets(self):
        self.assertEqual(check_brackets("[({]})"), False)

    def test_math_expression(self):
        self.assertEqual(
            check_brackets("(((185 + 223.85) * 15) - 543)/2"), True)

    def test_complex_latex_expression(self):
        self.assertEqual(
            check_brackets(
                ("\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{"
                 "x} &... x^2 \\end{array}\\right)")), True)


if __name__ == '__main__':
    unittest.main()