Week 5 was a really long one. We started our project fairly early and had I/O working before the end of the weekend, but all the data structures involved in our solution for the Austrian Voting project sent us through hoop after hoop. I’m going to focus on the biggest lessons I learned from testing and debugging our code, sometimes even a whole day or two was spent on the same error.
1. When in doubt, print line it out.
I cannot stress how invaluable being able to do print lines of the current state of our data structures is. We used tests from the shared test repo to test a lot of our code from the beginning. We managed to use the cases we failed on to find an usual error by showing how the ballots were moving around after each call of the method. I am pretty sure we would have never caught our error if it was not for this.
2. When you think you have tested for all edge cases, think again.
We really thought our code was correct on Tuesday when we were attempting to run it through the UVa testing program. Sadly, it was getting a runtime error. We had no idea why. It ran perfectly fine for over 25 test cases. We started thinking, “What causes runtime errors?” We figured it might be a segmentation fault. It was then when we realized that even though we had been testing very large test cases none of them had reached 1000 ballots. It was obvious what we needed to fix then.
3. Python scripts are your best friend when it comes to testing.
I’ve used Python scripts in the past to do automated testing at work. Even in simple test cases like these just writing a short script can help you make better acceptance tests that ensure you are testing all edge cases. We really should have made a 1000 ballots case of our own at the beginning and not just the end.
In retrospect, we could have probably made our code more efficient with less data structures, but it was just how we planned it at the beginning and slowly we realized we needed even more data structures. We did optimize some of them in the end. I am going to try to think more ahead in future projects in this aspect.