|Programming Project 2|
First, we re going to write a function to check when a pixel is inside the image of a number. Since we want to
keep this project simple, we'll use very small 3x4 images, and think of them as grids. We'll say that a grid is made up
of tiles. The
We will define the five images of the numbers "one" through "five" as the following:
IMPORTANT: To make this problem more reasonable than just using a "brute force" algorithm (which would require more code and potentially take much longer to write), and to practice some of the boolean logic constructs we've discussed, your code must not use more than four boolean operators with any conditional statement; otherwise, you will not receive credit for your function, even if it passed test cases on Marmoset. For example, the following conditional:
uses the maximum four boolean operators allowed (and, or, or, and).
This conditional conditional:
uses five boolean operators, and is disallowed (would NOT earn credit).
Remember that simply putting operators on different lines in python (we have not learned how to do this, but it is possible), does NOT count as reducing the number of operators, as your conditional still requires the same amount of operators. In addition, your function must be less than 25 lines of code, otherwise it's easy to just brute-force the solution.
For the second function, we're going to write a very specific function to identify empty pixels for just the number three.
How do you know what other shapes of three look like? Here are some rules:
checkTileand one test case of
isEmptyOnThree. Each test case is two lines long: the first line contains the name of the function, followed by a space, followed by all of the arguments to the function, each separated by a single space, and terminated by a newline. Then, on the next line, you should provide the expected answer for that function call, terminated by a newline. In your tests, make sure you include spaces where they need to be, otherwise they will not pass on Marmoset. Make sure to include a newline (blank line) after your last test case.
tests.txtfile to something that Marmoset will understand. We have provided a file for you, called DriverBuild.class (right-mouse click and save this file into the same directory as all of your other files for this project). To use this file, from a terminal in that directory, type:
java DriverBuild tests.txt
DriverJava.javathat you will submit as your test cases for this project. Note that you do not need to know or worry about how
DriverBuild.classworks (you will be learning about Java in CS211 if you take it), except each time you type the commands above, it will overwrite any older version of
DriverJava.javain that directory. Note that this is a delicate process, and if your test cases are malformed in any way, the
DriverBuildprogram will not be able to correctly convert them to something that Marmoset understands. If you see any error messages from Marmoset regarding "compilation", this means that your test file was not properly formatted, so you need to go back, fix the format, re-run
DriverBuild, and resubmit to Marmoset. Marmoset will grade the quality of your test suite.
project2.py(and remember the link to the template for this file above). You should get started writing your python code as soon as all of you finish your test suite and it passes both the public and release tests on Marmoset -- do not wait!
returnstatement to get your functions to return a value - DO NOT use the
driver.pyfile that will use your
tests.txtfile and print out whether or not the tests you wrote passed or failed, on the python code you wrote. To use this driver, make sure your
driver.pyare all in the same directory, and from a terminal in that directory, type:
stopon a single line after the last test you want run.
#. Note that you DO NOT have to comment out your print statements to run your test suite at home using
driver.py. Marmoset submission should be a last and rare step!
tests.txtabove: these tests are the Public Tests on Marmoset.
DriverJava.javafile (see above for how to convert your
tests.txtfile into this
DriverJava.javafile) on Marmoset following the link to CS112-2T. (The T stands for TEST)
project2.py. Normally, Marmoset is set up to work with Java files, which is why we have this workaround. Submit ONLY your
SystemCall.javafiles on Marmoset following the link to CS112-2C. (the C stands for CODE). Find the link on Marmoset to submit Project 2. Once you pass all the public tests, use your tokens wisely to start examining the release tests. Do not change the name of the files.