Re:Solving Algorithmic Problems in Python with Pytest (2019)
by mlthoughts2018 on Saturday December 19, 2020 @08:49AM
(#25477379)
“How do I test all possible equivalent definitions of this function” is probably not practically answerable for this. What if they wrote this?
def biasedcoin(n, p):
for answer in answer_key[n][p]:
yield answer
Or this: def biasedcoin(n, p):
while True:
mine_bitcoin_on_teachers_computer()
Re:Solving Algorithmic Problems in Python with Pytest (2019)
by madsbuch on Saturday December 19, 2020 @10:19AM
(#25477899)
Sure, this is simple! You provide them with a definition written in Coq and make them implement a proof that their implementation satisfies that definition. Use probabilistic couplings to make sure the output of the biased coin function adheres to specified distribution.
You can easily implement a grader that checks the the proof.
I am trying to write tests to autograde some HW assignments, and so I really have to think adversarially and imagine my students writing the weirdest yet correctly working functions.
I really haven't come up with a better answer than checking the statistics of the returned value by running the function a whole bunch of times, like you suggest.