Question: Lab03 - Exercise - Prefix (1 point) Open prefix.py and complete the function prefix_search() according to its documentation. Some tests have been added in prefix_test.py.


Lab03 - Exercise - Prefix (1 point) Open prefix.py and complete the function prefix_search() according to its documentation. Some tests have been added in prefix_test.py. Ensure your solution passes those tests then write some of your own such that you have 100% code coverage of prefix.py. To measure the coverage run coverage run-m pytest from the root of this repo. To view the coverage report use coverage report. You can see your coverage percentage in the indicator at the top of this page. It will update after the pipeline completes. Note that the pipeline will only fail if tests fail, so you need to pay attention to both the pipeline success/failure and also the coverage percentage. Please note: Coverage is not covered until the week 3 lectures, so you may not be able to complete part of this lab until then 2 3 4 5 6 7 8 9 10 11 prefix.py x prefix_test.py 1 def prefix_search(dictionary, key prefix): Given a dictionary (with strings for keys) and a string, returns a new dictionary containing only the keys (and their corresponding values) for which the string is a prefix. If the string is not a prefix for any key, a keyError is raised. You can assume that you will not be given any empty strings in dictionary or as key prefix For example, >>> prefix search({"ac": 1, "ba": 2, "ab": 3). "a") {'ac': 1. 'ab': 3) pass from prefix import prefix_search import pytest def test documentation (): assert prefix_search({"ac": 1, "ba": 2, "ab": 3}, "a") == { "ac": 1, "ab": 3} def test_exact_match(): assert prefix_search({ "category":"math", "cat": "animal"), "cat") == {"category":"math", "cat": "animal"}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
