The problem with A2 is that testing for all cases was extremely difficult to do. This was because the strategy was based on randomness and probability. There was always a certain degree of uncertainty as to whether the code worked or not because it simply could have randomly chosen the correct answer without actually applying the strategy. For each test case, there is a probability that it passes the test case based upon the random strategy. But take multiple test cases and multiply the chances of the case passing based on randomness becomes smaller and smaller. So for example if test 5 test cases all had a 50% chance of passing and the 6th had a 20% chance of passing, that means that the probability of all the cases passing from randomness is only 0.00625%. This ensures that you feel a lot safer knowing your code almost certainly works and not just based off the randomness factor. This was a very important concept to learn to minimize the chance of error in your code. This proves that choosing good test cases and having many of them are very important in ensuring your code runs smoothly.
The other things we learned were implementing unit test cases and deep copies. We touched on unit tests briefly since most of the class who had taken CSC108 had experience with unit tests. We learned about deep copy and how it was important in A2. Having a copy at every level of your program ensures that GameState is never changed. My partner and I had already implemented a sort of deep copy in A2 so this was not something new.
On Wednesday we learned more about assertions in unit test cases. Assertions help state what we know is true at a certain point in the code and also at the beginning of the code. Assertions raise an error if the certain condition fails. This part of unit tests are very important as they point out the mistakes to you or someone else editing your code. It points out important bits of knowledge that could be useful during coding and also in the future (during updates). There aren't really any downsides to assertions so you should use them frequently. I found this part to be very useful since it will become a great time saver for code you need to continuously maintain and update.
![]() |
| Don't slack off! Write some unit tests! |









