Question: For this project, you will write a test function, test_sscount . test_sscount will automate testing of sscount0 and sscount1 from the second picture. test_sscount will


For this project, you will write a test function, test_sscount . test_sscount will automate testing of sscount0 and sscount1 from the second picture.
test_sscount will each have three parameters. The first parameter is f, a function which
will be sscount0 or sscount1. (As you will see in lab this week, Python functions can be
passed as arguments to a function in the same way as other data types.) The second argument is
args, a string with the needle and the haystack strings, separated by one space character.
The final argument is expected_result, an integer which is the expected result of calling
one of the sscount functions for the needle and haystack strings in args.
test_sscount will call f for the needle and haystack string in args, and compare the
result returned by f to the expected result. For each test case, test_sscount should report
whether the actual result matches the expected result, for example:
testing sscount0
Checking sses assesses
its value 2 is correct!
Function test_sscount should return None.
Next, write a main function that calls test_sscount two times once to test sscount0
and once to test sscount1, for a series of test cases. For example,
test_sscount(p34.sscount0, 'sses assesses', 2)
test_sscount(p34.sscount1, 'sses assesses', 2)
main should include calls to test_sscount for at least the following test cases (and expected
results):
'sses assesses', 2
'an trans-Panamanian banana', 6
'needle haystack', 0
'!!! !!!!!', 3
'o pneumonoultramicroscopicsilicovolcanoconiosis', 9
'', 0
'a ', 0
' abc', 0
'a a', 1
Note that at least one of the edge cases will reveal an issue with the posted solutions and/or the
specification for project 3-4. Comment on this in your .py file.
The last line in your .py file should be a call to function main.
I put a picture of what I have so far. I'm struggling really with my for loops so any advice or explanation would be great!
Thanks
*p41_testfuncs.py - /Users/Halle/Desktop/p41_testi def test_sscount(f, args, expected_result): (function, str, int) --> test sscount will automate testing of sscounte and s: Parameter will be function sscounte or sscount1 Parameter args is a string with the "needle" and the strings, soporated by one space character. expected result parameter 1$ an integer which is the or calling one of the secount functions gfor the need stings in args. will return None. Examples Checking sses assesses its value 2 is correct needle = haystack = 44 For chin args. 1 ch = 1 needle += ch for chin args. ich = 1 haystack += ch result = f(needle, haystack) 10 result == expected result print('its value result is correct) OSCH printit Malue, result, is incorrect natur Non main mainwin1 cabosticscount twice to test bothsscounta, *p34 sscount_key.py - /Users/Halle/Desktop/p34_sscount_key.py (3.7. def sscounte (needle, haystack): estr str --> int Given a "needle string to search for in a "haystack" string, return the count of the number occurrences of the needle in the haystack Overlapping substrings are included. Users string slice operation only). >>> sscount esses! Lassesses) 2 >>> sscountean trans-Panamanian banana) ET ctr = 0 n = len(needle) for i in range(len (haystack)): if haystack[i:i+n] == needle: ctr += 1 return ctr det sscount (needle, haystack): Instr, str> int Given a needle" string to search for in a "haystack string, return the count of the number occurrences of the needle in the haystack. Overlapping substrings are included. Using string startswith method simplifies code a bit. ops poll Ma >>> sscountiisses 2 assesses ctr = 0 Rel for i in range(len (haystack)): Ebo if haystack[i:]t startswith(needle): ctr += 1 ces return ctr ong #print(doctest.testmod) Ln: 38 Col: *p41_testfuncs.py - /Users/Halle/Desktop/p41_testi def test_sscount(f, args, expected_result): (function, str, int) --> test sscount will automate testing of sscounte and s: Parameter will be function sscounte or sscount1 Parameter args is a string with the "needle" and the strings, soporated by one space character. expected result parameter 1$ an integer which is the or calling one of the secount functions gfor the need stings in args. will return None. Examples Checking sses assesses its value 2 is correct needle = haystack = 44 For chin args. 1 ch = 1 needle += ch for chin args. ich = 1 haystack += ch result = f(needle, haystack) 10 result == expected result print('its value result is correct) OSCH printit Malue, result, is incorrect natur Non main mainwin1 cabosticscount twice to test bothsscounta, *p34 sscount_key.py - /Users/Halle/Desktop/p34_sscount_key.py (3.7. def sscounte (needle, haystack): estr str --> int Given a "needle string to search for in a "haystack" string, return the count of the number occurrences of the needle in the haystack Overlapping substrings are included. Users string slice operation only). >>> sscount esses! Lassesses) 2 >>> sscountean trans-Panamanian banana) ET ctr = 0 n = len(needle) for i in range(len (haystack)): if haystack[i:i+n] == needle: ctr += 1 return ctr det sscount (needle, haystack): Instr, str> int Given a needle" string to search for in a "haystack string, return the count of the number occurrences of the needle in the haystack. Overlapping substrings are included. Using string startswith method simplifies code a bit. ops poll Ma >>> sscountiisses 2 assesses ctr = 0 Rel for i in range(len (haystack)): Ebo if haystack[i:]t startswith(needle): ctr += 1 ces return ctr ong #print(doctest.testmod) Ln: 38 Col
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
