Question
HOW TO PASS THE TEST CASES WITH THE QUESTION import unittest def balance_brackets(string): Write a function balance_brackets(string), which checks if the given
HOW TO PASS THE TEST CASES WITH THE QUESTION
import unittest
def balance_brackets(string):
"""
Write a function balance_brackets(string), which checks if the
given string has balance brackets.
For example, balance_brackets('(a)+(b)') returns 'True'.
.
Note that your program has to work for any input string.
"""
pass
# --------------------------------------------------------------
# The Testing
# --------------------------------------------------------------
class myTests(unittest.TestCase):
def test1(self):
self.assertEqual(balance_brackets('()()'), True)
def test2(self):
self.assertEqual(balance_brackets('))(('), False)
def test3(self):
self.assertEqual(balance_brackets('(a+b)+c'), True)
def test4(self):
self.assertEqual(balance_brackets('(a+b)+c)'), False)
def test5(self):
self.assertEqual(balance_brackets(''), True)
if __name__ == '__main__':
unittest.main(exit=True)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started