Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fonglh opened this issue Oct 6, 2016 · 2 comments
Open

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

fonglh opened this issue Oct 6, 2016 · 2 comments

Comments

@fonglh
Copy link
Member

fonglh commented Oct 6, 2016

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
Copy link

mattjegan commented Oct 6, 2016

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
Copy link
Member Author

fonglh commented Oct 6, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants