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'); Assert.That(calc1.GetOutput(), Is.EqualTo("1")); calc1.AcceptCharacter('2'); Assert.That(calc1.GetOutput(), Is.EqualTo("12")); calc1.AcceptCharacter('c'); Assert.That(calc1.GetOutput(), Is.EqualTo("0")); }
public void CalculatorStartsOffShowingZero() { // Make a new calculator controller // Check that GetOutput() is equal to "0" CalculatorController calc1 = new CalculatorController(); // The two following lines are equivalent. One uses the "constraints" model, and one uses the "static test assertions" model. Assert.That(calc1.GetOutput(), Is.EqualTo("0")); // Google "NUnit constraints" Assert.AreEqual(calc1.GetOutput(), "0"); // Google "NUnit static test assertions" // In this class, we will prefer the constraints-based approach, as it reads more like English and gives more detailed // and precise failure messages. // It also avoids the ambiguity as to which parameters is the "expected" result and which is the "actual" result. }
private void ButtonClearClick(object sender, EventArgs e) { // Someday, this method will reset the calculator controller to a "like-new" state. // I added it to the public interface of the CalculatorController class so that tests // can share a CalculatorController instance -- they just need to call "Clear" before // each test. _controller.AcceptCharacter('c'); output.Text = _controller.GetOutput(); }
public Form1() { InitializeComponent(); output.Text = _controller.GetOutput(); }
public Form1() // Defines Form1 { InitializeComponent(); // AEH Initialize the buttons and textbox output.Text = _controller.GetOutput(); // AEH Do GetOutput and put what it returns in textbox. }
// 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 ButtonClearClick(object sender, EventArgs e) { _controller.Clear(); output.Text = _controller.GetOutput(); }