Beispiel #1
0
 public void EnsureICanExtractOperator()
 {
     // Arrange
     Parse aParse = new Parse();
     string anOperator = "*";
     // Act
     aParse.ParseInput("5 * 2");
     // Assert
     Assert.AreEqual(anOperator, aParse.Operator);
 }
Beispiel #2
0
 public void EnsureICanExtractInputTerms()
 {
     // Arrange
     Parse aParse = new Parse();
     string firstTerm = "1";
     string secondTerm = "8";
     // Act
     aParse.ParseInput("1 + 8");
     // Assert
     Assert.AreEqual(firstTerm, aParse.Terms[0]);
     Assert.AreEqual(secondTerm, aParse.Terms[1]);
 }
Beispiel #3
0
 public void EnsureICanParseInputWithSecondTermNegative()
 {
     // Arrange
     Parse aParse = new Parse();
     string anInput = "1 + -1";
     int firstTermExpected = 1;
     int secondTermExpected = -1;
     string operatorExpected = "+";
     int firstTermActual;
     int secondTermActual;
     // Act
     aParse.ParseInput(anInput);
     int.TryParse(aParse.Terms[0], out firstTermActual);
     int.TryParse(aParse.Terms[1], out secondTermActual);
     // Assert
     Assert.AreEqual(firstTermExpected, firstTermActual);
     Assert.AreEqual(secondTermExpected, secondTermActual);
     Assert.AreEqual(operatorExpected, aParse.Operator);
 }
Beispiel #4
0
 public void EnsureICanRemoveInappropriateWhiteSpace()
 {
     Parse aParse = new Parse();
     aParse.ParseInput("8          2     +23210 7     ");
     string expected = "82 + 232107";
     Assert.AreEqual(expected, aParse.Expression);
 }
Beispiel #5
0
 public void EnsureInvalidInputThrowsAnError()
 {
     // Arrange
     Parse aParse = new Parse();
     string anInput = "1 + - 1";
     aParse.ParseInput(anInput);
 }