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
58
59
60
import unittest

from bracket_push import is_paired


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

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

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

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

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

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

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

    def test_partially_paired_brackets(self):
        self.assertEqual(is_paired("{[])"), False)

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

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

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

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

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

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

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

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


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