Question
1. Create a new Python project in PyCharm. 2. One file,BalancedAB.py will contain the main function described in the next item. 3. Define a function
1. Create a new Python project in PyCharm.
2. One file,BalancedAB.py will contain the main function described in the next item.
3. Define a function BalancedAB(string st) which is a Boolean function that returns True if for every A character in a string of uppercase letters and spaces, there exists a B character to be found somewhere later in the string.
4. Hint: the method rindex() in Python returns the last index where a certain substring str\ is found, or raises an exception if no such index exists: str.rindex(str, beg=0 end=len(string))
(a) str : This specifies the string to be searched.
(b) beg : This is the starting index, by default its 0.
(c) len : This is ending index, by default its equal to the length of the string.
5. In the second file, Test BalancedAB.py , you will define your own class derived from unittest.TestCase. Then, you need to fill it with functions that start with test . Finally, you need to run the tests by placing unittest.main() in your file, usually at the bottom.
6. Create nine test cases for each of the following possible outcomes. The name of each test method should be the string TestBalancedAB, followed by an integer digit:
1 BalancedAB(AAZZBB) true
2 BalancedAB(AAAXXXXYB) true
3 BalancedAB(BBYYYXXXAXX) false
4 BalancedAB() true
5 BalancedAB(XXXXXYYYYZZZZB) true
6 BalancedAB( XXXXXYYYYZZZZ) true
7 BalancedAB(XXXX XYYYY ZZZZB) true
8 BalancedAB(YYYBABYYYXXXAXX) false
9 BalancedAB(ABABABA) false
7. Make any necessary corrections to the class under test until all unit tests pass.
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