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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!