Saturday, March 21, 2015

Assert, Unit Tests and Call Stacks

    This week we learned about asserts and how to make assertions. Assertions are extremely helpful when it comes to debugging because instead of executing your code line by line in the debugger or printing something after every line or so it will only print when the code does something you didn't expect it to do. In other words, it will print a message telling where things went wrong even though you didn't expect it to go wrong! Pretty useful eh?

    Another thing we covered was coming up with good test cases for unit testing. An exercise we did was figuring out what makes a good test case and what doesn't. So with that being said we starting to come up with test cases to see if our minimax strategy was working properly. We looked at different test cases for minimax being used with our game, subtract square, and we tried to figure out if the test case provided us with information on if our minimax was working. properly. We looked at 3 test cases for subtract square; 9, 10, and 11. After looking at the possible number of winning moves or losing moves each current total for subtract square provided, we concluded that either very little information is given or no information is given about whether or not our minimax was working properly. We then concluded that in order for us to come up with a good test case, the test case required more losing moves than winning moves. Thus we came up with test cases with only 1 winning move and 4 losing moves; 25, 27, 28, and 29. Since these test cases had only 1 winning move and 4 losing moves, the probability of winning all 4 games was (1/5)^4 which is about a 0.16% chance of our minimax NOT working properly but still leading us to the winning move by randomly selecting a move...

    The last thing we covered was the function call stack. At first I was like "what's a function call stack" and about 20 seconds later it hit me... It's pretty much what the name says it is... A stack of function calls. HAHAHAHA! We did an example to show how each function call is added onto the stack and once it has finished it's job it gets removed from the stack and we go back to finish the previous function call.

No comments:

Post a Comment