Matrix

Sunday, 22 March 2015

Assertions, Unit Tests, and A2

This week's focus was on unit tests, revisiting A2 and using deep copies, and assertions.

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!

Monday, 16 March 2015

Week 9: Term Test 2, BST Mutation

This week was shortened by the second term test and we briefly discussed mutation of binary search trees on Monday. I found the second term test to be fair and I think I did well.It covered binary trees, some recursion, and linked lists. Like the first, it required you to study the labs throughout. Hopefully, the TAs will finish the strike soon so we can get lab practice again.

We were given a handout about binary search tree mutation in the lecture. It involved writing a binary search tree, looking at the key elements of it (class BTNode and class BST), and then implementing some mutation using the insert and delete functions. It was a relatively easy exercise and didn't take long considering I had spent the last two weeks studying binary trees for the term test.

We did some basic review for the term test on Monday as well. We looked over some labs, discussed the test, and reviewed key concepts. It was a fairly straightforward lecture and was to be expected considering the other half of lectures that week would be composed of the term test.


Saturday, 7 March 2015

Week 8: Strikes, LinkedLists, and Mutating

This week did not have a lab due to the unfortunate timing of the TA strike. Nonetheless, I worked on the lab at home and went to the lectures. Without the help from the TAs and the lab environment, the concepts taught this week were obviously more difficult to understand. The central focus of this week was linked lists, how to manipulate them, and how to traverse through them.

Basic structure of the linked list

Linked lists are essentially a linear sequence of nodes. A linked list can be seen in two ways but the way we focused on during lecture was viewing it as a sequence of nodes, each with a value and a reference to the next node. The primary benefit of using linked lists is that it allows you to easily insert or remove list elements without shifting the whole structure. Values can be added or removed at any point in the list.

We also took a quick look at some pseudo code to help understand how moving through a linked list works. We also took a look at mutating linked lists. Mutability of lists is something we explored in CSC108 where the contents of the list can be changed. Our professor explained the basic concept and will expand more about mutability into trees and such in the coming weeks.

Not this kind of mutating
Overall, this week was not very hard to learn and understand. The tricky part was obviously tackling the lab by myself but I managed to figure it out at the end. Linked lists are an important concept to learn because it seems like a very efficient way to add/delete instances of list elements. This seems useful in real life computing where time predictability is important. It also seems to leave more room to grow as you don't necessarily need to define the size of the list from the get go. Compare this to something like an array where you need to re-declare and copy the elements if the array gets to big, and it becomes a very useful tool in saving time. Hopefully the strike doesn't last too long and we can get back to learning in the labs as well.
Matrix