Please note, this blog entry is from a previous course. You might want to check out the current one.
Update the user-interface of your Calculator to test all of the above.
a. Your UI should already have a UILabel which shows what has been sent to the brain. Change it to now always show the latest description of the program currently in the CalculatorBrain using your descriptionOfProgram:method. It should show the description without substituting variable values (obviously, since descriptionOfProgram: does not take a variable value dictionary as an argument).
b. Add a few variable buttons (e.g, x, y, foo). These are buttons that push a variable into the CalculatorBrain.
c. Change your calculator to update its display (as needed) by calling your new runProgram:usingVariableValues: method. The variable values dictionary it passes to this method should be a property in your Controller (let’s call it “testVariableValues”).
d. Add a UILabel to your UI whose contents are determined by iterating through all the variablesUsedInProgram: and displaying each with its current value from testVariableValues. Example display: “x = 5 y = 4.8 foo = 0”.
e. Add a few different “test” buttons which set testVariableValues to some preset testing values. One of them should set testVariableValues to nil. Don’t forget to update the rest of your UI when you change testVariableValues by pressing one of these test buttons. Make sure that your preset values are good edge-cases for testing (we are intentionally not telling you what to use since part of good programming is figuring out how to thoroughly test your application).
To solve #a just remove all occurrences of code where you have manipulated the history label from CalculatorViewControler.m and replace it by
self.history.text = [CalculatorBrain descriptionOfProgram:self.brain.program];
which will render removeEqualSignFromHistory obsolate, so you might want to remove this helper function, too.
Continue reading “Assignment #2 Task #3”