public Form1() { InitializeComponent(); _controller.ResetCalculatorState(); _controller.AcceptCharacter('c'); output.Text = _controller.GetOutput(); }
public Form1() { InitializeComponent(); _controller.AcceptCharacter('c'); output.Text = _controller.GetOutput(); KeyPreview = true; }
public void CalculatorClearButtonResetsValueToZero() { // Make a new calculator controller // Enter a non-zero number // Click the clear button // Assert GetOutput() is equal to "0" CalculatorController calc1 = new CalculatorController(); calc1.AcceptCharacter('1'); calc1.AcceptCharacter('c'); Assert.That(calc1.GetOutput(), Is.EqualTo("0")); }
// I noticed that the same basic code was showing up in all of the methods: // output.Text = _controller.AcceptCharacter('?') // Whenever I see duplicated code, I want to get rid of it -- it's more places where // errors can occur, more things I have to read over to find the "meat" of the code, // more stuff to modify and maintain if I want to make a change later. // // So, I wrote this "helper method" to encapsulate the redundant "boiler-plate" parts of // that code. Now, each button-click handler just says // handleInput('?')" // and it's really easy to visually verify that each method does the intended thing. private void HandleInput(char input) { _controller.AcceptCharacter(input); output.Text = _controller.GetOutput(); }
private void HandleInput(char input) // AEH Defines a helper method for each button click. { _controller.AcceptCharacter(input); // AEH Call AcceptCharacter (and its return). output.Text = _controller.GetOutput(); // AEH Call GetOutput, and put its return in the textbox. }