View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Joel Uthe

CoWeb Assignment 2



Uploaded Image: Error.jpg

The Debugger is very useful to solve programming bugs. Whenever an error is generated, the option to use the debugger is always available. The nicest and most useful part of the debugger is that you can look at all the Objects and their value during anypoint of the stack trace. So if an error is created in a method, it may be because of something done before it. Thus you can look at the previous message calls and see if the Object you are looking for is valid in a previous part of the program. For example, there was a point where I was searching a Collection for a Character. If this character wasn't in the Collection, then it would return an empty Collection. Unfortunatley, it was returning empty Collections even though I know I placed the Character into the Collection. So when the error was thrown, I entered the debugger and and was able to trace back up the stack trace and look at all the values that were included in the Collection at different points during the program. It was a lot easier then having millions of output statements, and then never being able to find them all when we make releases of the program.

Uploaded Image: Debug.jpg

Like many other debuggers in other languages, Squeak's debugger can step over and into different methods. This is even nice when it is combined with thte fact that Squeak is interpreted at runtime so you can change code while in the debugger and then run/test your method. Overall, I would consider it the most useful tool in Squeak.

Midterm Review



Writing Code
Implement a method in Squeak that will give you the nth Fibonacci number. For both 0 and 1, the Fibonacci number equals 1. From then on, the next in the series is simply the sum of the previous two in the series (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.). Return an error when applicable. Your code should be based on good OO-style and be an efficient algorithm.

fib: number
	(number < 0) ifTrue: [self error: 'Enter a positive number.'].
	(number < 2) ifTrue: [^1].
	^((self fib: (number - 2)) + (self fib: (number - 1))).



Unit Testing
What are the setUp and tearDown methods used for in SUnit testing? Give an example of where you would have to use a tearDown method. Though SUnit and JUnit are the same frameworks, they work a bit differently. Explain why they work differently.

The setUp method is called before each method test in SUnit testing, and the tearDown method is called after each method test in SUnit testing. You may need a tearDown method to reset class variables that shouldn't be reset before every test in setUp, but only after certain method tests. SUnit is for Squeak and JUnit is for Java, so they work a little bit differently. Squeak sends messages to the assert object, while Java has assertTrue and other methods.


Links to this Page