Ejemplo n.º 1
0
    def test_04(self):
        """ Moderately sized sequences """
        sequence = '([()]([]))[[[]()]][[[[[]]]]]([([([])])])'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([()]([]))[[[[]()]][[[[[]]]]]([([([])])])]'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '(([()]([]))[[[[]()]][[[[][[]]]]]([([([)])])])]'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '([()](([]))[[[]()]][[[[[]]]]]([([([])])]))'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([()]([[]))[[[]()]][[[[[]]]]]([([([])])]))'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '([()]([[]))[[[]()]][[[[[]]]]]([([([])])]))'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = ']' * 20 + ')' * 20
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '([' * 20
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '(' * 10 + ']' * 10
        self.validate(False, quiz2.is_balanced(sequence))
Ejemplo n.º 2
0
    def test_01(self):
        """ Sequences with only one kind of bracket """
        sequence = '()'

        self.validate(True, quiz2.is_balanced(sequence))

        sequence = ']['
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '()())'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '][[]]'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '(()())'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '(()()))(()()'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '[[]][][][][[]]][[]]'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '(())((())()()(())(()())'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '((()(()))())(((((((())))))))()()()'
        self.validate(True, quiz2.is_balanced(sequence))
Ejemplo n.º 3
0
    def test_02(self):
        """ Small sequences with both types of brackets """
        sequence = '[]()'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([])'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([)]'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '(][)'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '[[()][]()]([()[[]]])'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '[[](]())'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '[(])[[(())]][((]))'
        self.validate(False, quiz2.is_balanced(sequence))
Ejemplo n.º 4
0
    def test_03(self):
        """ Deeply nested sequences """
        sequence = '([[([[((([((([((([[]])))])))])))]])]])'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([[([[((([((((((([[]])))])))])))]])]]))'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '[' * 10 + ']' * 10 + '(' * 11 + ')' * 11
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '[((' * 10 + '))]' * 10 + '([' * 11 + '])' * 11
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '[[((' * 10 + ']]))' * 10 + '[](())'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '([[' * 20 + '))]' * 20 + '(' * 30 + ')' * 30
        self.validate(False, quiz2.is_balanced(sequence))
Ejemplo n.º 5
0
    def test_05(self):
        """ More moderately sized sequences """
        sequence = '[[((())))(]]'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '()' * 20 + '[]' * 20 + '(' * 20 + ')' * 20
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '()' * 20 + '[]' * 20 + '[' + '(' * 20 + ')' * 19 + ']'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '()' * 20 + '[]' * 20 + '[' + '(' * 20 + ')' * 19 + ']'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = ')' * 10 + '(' * 10 + '[' * 10 + ']' * 10
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = ']' * 10 + '[' * 10 + '(' * 10 + ')' * 10
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '((((((([[[[[[)))))))]]]]]]'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '(([([[[()]]])][[()(([()]))([])](())[()]]))' * 10
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([[((([[[[((((([[[[[[((((((([[[[[[[[((((((((([[[[[[[[[[]]]]]]]]]])))))))))]]]]]]]])))))))]]]]]])))))]]]])))]])'
        self.validate(True, quiz2.is_balanced(sequence))

        sequence = '([[((([[[[((((([[[[[[((((((([[[[[[[[((((((((([[[[[[[[[[]]]]]]]]]])))))))))]]]]]]]])))))))]]]]]])))))]]])])))]])'
        self.validate(False, quiz2.is_balanced(sequence))

        sequence = '(([[)])]' * 20
        self.validate(False, quiz2.is_balanced(sequence))