Testing and More Testing
A problem that I’ve been trying to solve is testing a file without functions and the file uses random.randInt(). I know about seeding the random so it’s consistent every time, so that’s not a problem. The problem is using that in conjunction with a file without functions.
The context is I’m having my students make a Blackjack game with if / else statements and while loops before they learn about functions, and then they’re going to learn about functions, identify the repetitive parts, and then write and unit test those functions. They’ll then call those functions to play Blackjack the same way their original no-functions code did it.
To generate a card hand, random.randInt() will generate a number between 1 and 13, inclusive. To test this, it has to be the same which is fine. But, I had no idea how to do it without using functions, because nothing on the internet seems to talk about this.
I also asked three past GIR instructors who have used Mimir and reached out to Mimir tech to see whether this can be done. Mimir tech is pretty bad; they just keep throwing documentation at me without reading my question or trying to understand it. Or maybe I’m bad at describing my problem, but why does everyone else I describe my problem to understand me fine?
Anyway, the GIR instructors basically said they don’t know or it’s not possible. That’s not good. I brainstormed some solutions, and after deciding to wrap the solution code in a function, I wrote unit tests with seeded random integers and it worked. I was so excited to see that work.
Now, I just have to figure out how to wrap the student’s solution code into a function to run. I’m thinking I’ll go through line by line and write out a new file to run, but that seems error prone.
I’m doing surprisingly a lot of coding for teaching. But only because I’m so against grading by hand because I just really don’t want to spend all my time reading code. Plus, coding is a lot more fun than reading code, so there’s that!
It’s also a relief to find out that once a student submits to Mimir, the autograder runs and will tell them what’s wrong right away. I was a bit scared that it would wait until the deadline to run, in which case students wouldn’t get feedback right away.
I do really feel like somehow, I’m able to think of creative solutions to all these testing problems. It’s a bit ironic that I’m spending so much time thinking about testing when that’s my least favorite part of my actual job. I guess it does just all come around, doesn’t it?