Unit tests for Udacity CS373 homeworks
git(to clone the repo ;) )
python-2.x(tested with 2.7.2, but probably works with 2.6 too)
- text editor of your choice
Clone the repo (if you haven't done already):
$ git clone git://github.com/DirtYiCE/cs373-tests.git $ cd cs373-tests
Make sure you have set
$EDITORto your favourite text editor, then issue:
$ ./test.py <homework_number> edit
<homework_number>is in format like
1.4for the 4th question in the first homework. You can also copy
<homework_number>/code.py(if exists, otherwise just create a new file), then open it with your editor.
It may be an empty file, do not worry. It will set the given variables to the given values before executing your code. You actually only have to write the part after the "do not modify anything before" lines, and you also don't have to print it (just place in the correct variable). If you're not sure, open
<homework_number>/template.pyand search for
# !code!. Your code will be executed like you placed your code there.
For example, given a task to add two numbers together, you would get something like this to edit:
a = 4.0 b = 5.0 # ENTER CODE BELOW c = 0.0 # You must print it with the following code: print(c)
Then, when you run
./test.py <num> edit, you only have to enter
c = a + b
And it will work like you just inserted it after
c = 0.0.
When you think you should test your code, with the examples given in the homework assigment, run:
$ ./test.py <homework_number>
If all test passes, you will see an
OKat the end of output. Otherwise it will tell you which tests failed, the expected and your output.
When you are done, simply paste your code into the correct place in the web interface. Alternatively, you can use
$ ./test.py <homework_number> format
to print your code (to the stdout) with all the required header and footer stuff. If you use
format, it will run the code in python, just to check if everything is right.
You will probably want to run the code before saving it (in the browser), just in case Udacity's python handles somehing differently.
General syntax is:
$ ./test.py <homework_number> [command] [arguments]
command defaults to
test when not specified. Available commands:
edit: open your solution (
zap: deletes your solution
test: run the tests. Arguments you pass will be handled by python unittest.
format: place headers and footers around your solution, then print to stdout.
run: executes the output of
*/template.py files are from Udacity.
*/testcase.py also tend to contain
some Udacity code. Other files were written by me, and you're free to do
whatever you want do with them. They are available under the terms of
WTFPL, if you like that better.
This program is free software. It comes without any warranty, to the extent permitted by applicable law.
Use github's issue tracker or create a pull request with your patch.
This program doesn't contain the solution to the homework, nor tells you if they're correct. It justs tests that the example inputs given in the assigment produces the same output as in the video. It only saves you from manually typing the inputs then comparing the numbers (which is quite error prone). Otherwise, it gives you no advantage.