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

Unit test to grade input/output beginner exercises #245

Open
reingart opened this issue Mar 23, 2023 · 1 comment
Open

Unit test to grade input/output beginner exercises #245

reingart opened this issue Mar 23, 2023 · 1 comment

Comments

@reingart
Copy link
Member

Initial programs don't use def so they cannot be invoked in unit test to check results programmatically, for example:

https://pyar.github.io/PyZombis/main/lectures/TWP15/TWP15_3.html#algunos-ejercicios

But, we could include hidden code to wrap input and print functions, so later we can evaluate them.

Proof-of-Concept:

# wrap functions to store inputs and outputs
inputs = []
outputs = []

i = input
def input(msg):
    v = i(msg)
    inputs.append(v)
    return v

p = print
def print(v):
    p(v)
    outputs.append(v)

# student code:
n = input("n")
print(int(n) + 2)

# automatic check / grading:
assert not inputs, "your program must read input data"
assert not outputs, "your program must print output results"
assert outputs[0] == int(inputs[0]) + 1, "you must sum 1"

Documentation:
https://runestone.academy/ns/books/published/authorguide/directives/activecode.html#incorporating-unit-tests

@Ankityd
Copy link

Ankityd commented Oct 7, 2023

Hey, I would like to work to this issue please assign this issue to me.

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