This task is part of project08 which is due at 23:00 EST on 2022-11-16.
You have the option to work with a partner on this task if you wish. Working with a partner requires more work to coordinate schedules, but if you work together and make sure that you are both understanding the code you write, you will make progress faster and learn more.
You can download the starter code for this task using this link.
You can submit this task using this link.
Put all of your work for this task into the file
test_weather.py
(which is provided among the starter files)
In this task, you will practice writing test cases with optimism
by writing test cases to catch four incorrect implementations of a project for which we've already given you the solution file. You are not required to write any functions for this project, you only need to write test cases for provided functions.
We have given you a file called weather.py
which represents a correct solution to a fictional project task. It defines 3 functions: listFrostMonths
, tempsStartingFrom
, and rainOrShine
. We have also given you the files weather1.py
, weather2.py
, weather3.py
, and weather4.py
, each of which defines some of the three functions correctly but gets at least one wrong in some way. Your job is to write [at least 9 test cases](#goal:core.check:call-case) (more if you like) such that:
In other words: your test cases need to catch the incorrect files but let the correct file through.
You should read the docstrings provided in weather.py
to understand
what each function is supposed to do. Feel free to read the code as well,
and also use the shell to play around with them a bit to understand how
they are supposed to work. We have purposefully omitted any examples of
how they are supposed to behave, because coming up with those examples is
your job here.
You will write your test cases in the test_weather.py
file (which is
also the file you'll ultimately submit). We have already provided the
code that sets up one tester for each function, and at the top of the
file, there is a block of code that looks like this:
# TODO: Uncomment one of these lines at a time to select which file your
# tests are run on. These lines all rename the imported module to
# 'weather' so that you can write your tests using 'weather' as the
# target.
import weather
#import weather1 as weather
#import weather2 as weather
#import weather3 as weather
#import weather4 as weather
As it instructs, you can uncomment one of those lines and comment out
whichever one you had been using before to switch which of the five
supplied files your tests are run on. Just remember that when you submit
your file, the first import of just the weather
module must be
uncommented so that we can properly
test your code.
You should first focus on defining a few tests for each function that will pass when run against the correct submission. If you're lucky, that will be enough to catch all the incorrect submissions. If not, you should try the following:
When you've defined enough test cases that all of the incorrect files fail at least one test, you are done.
Remember that to define a test case, first use the case
method of a
tester
object and store the result in a variable, giving case
the same arguments you'd normally give to the function being tested.
Then, use the checkReturnValue
method of that case object to check
the result. The whole process looks like this:
tester = testFunction(max)
case = tester.case(3, 4)
case.checkReturnValue(4)
weather.py
and ensure that all of your tests pass.weather1.py
{mname}.py
and ensure that at least one of your tests fails (i.e., it catches an error in this incorrect file).weather2.py
{mname}.py
and ensure that at least one of your tests fails (i.e., it catches an error in this incorrect file).weather3.py
{mname}.py
and ensure that at least one of your tests fails (i.e., it catches an error in this incorrect file).weather4.py
{mname}.py
and ensure that at least one of your tests fails (i.e., it catches an error in this incorrect file).weather
module
weather
module.case
case
in at least 9 places.checkReturnValue
checkReturnValue
in at least 9 places.