Coursemology / evaluator-samples

Sample test packages for the code evaluator
0 stars 7 forks source link

Check for use of map/filter instead of loops #4

Open fonglh opened 8 years ago

fonglh commented 8 years ago

Some exercises are meant to teach students how to use functions like map and filter.

Write a test that passes when those functions are used and fails if loops are used.

mattjegan commented 8 years ago

I'm not sure this is possible unless you somehow check the code for occurrences of while and for since I believe you can re-write any use of map(func, iter) or filter(func, iter) as:

new_iter = []
for x in iter:
    new_iter.append(func(x))

and

new_iter = []
for x in iter:
    if func(x):
        new_iter.append(x)

respectively. My above examples could be collapsed using comprehensions but I wanted to leave them as clear as possible.

fonglh commented 8 years ago

Thanks for your input, to give some context, the code consists of sample test packages for the code evaluator at https://github.com/coursemology/evaluator-slave

This is used to teach an introductory programming course to first year college students. The code in submission/template.py is the initial code that is shown to the students. That file is then overwritten with the student's code.

The entire package is sent to the code evaluator, which runs make test, generating an xml file with the unit test report, which is then sent back to the app for parsing and display.

The samples here are examples to help the teaching assistants write tests which check for the correctness of the student's code and ensure they fulfill the lesson objectives.

It's fine to write a test that opens the file and checks the code, or perhaps override the build in map function and check that it gets called. The idea is to ensure that the student also fulfills the lesson objective of learning map and filter instead of just writing code that produces the desired data structure.