Exemple #1
0
 public void EnsureICanExtractOperator()
 {
     // Arrange
     Parse aParse = new Parse();
     string anOperator = "*";
     // Act
     aParse.ParseInput("5 * 2");
     // Assert
     Assert.AreEqual(anOperator, aParse.Operator);
 }
Exemple #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]);
 }
Exemple #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);
 }
Exemple #4
0
 public void EnsureInvalidInputIsInvalidated()
 {
     Parse aParse = new Parse();
     Assert.AreEqual(false, aParse.ValidateInput("13 + - 3"));
     Assert.AreEqual(false, aParse.ValidateInput("2 - - 3"));
     Assert.AreEqual(false, aParse.ValidateInput("-2 +- 3"));
     Assert.AreEqual(false, aParse.ValidateInput("- 1*3"));
     Assert.AreEqual(false, aParse.ValidateInput("2- - 1"));
     Assert.AreEqual(false, aParse.ValidateInput("+1+ - 2"));
     Assert.AreEqual(false, aParse.ValidateInput("-3/- 32"));
     Assert.AreEqual(false, aParse.ValidateInput("3 + - 3"));
     Assert.AreEqual(false, aParse.ValidateInput("20 - - 32"));
     //Assert.AreEqual(false, aParse.ValidateInput("-2 +/ 3"));
     Assert.AreEqual(false, aParse.ValidateInput("- 1*3"));
     Assert.AreEqual(false, aParse.ValidateInput("2- - 1"));
     Assert.AreEqual(false, aParse.ValidateInput("+1+ - 2"));
     Assert.AreEqual(false, aParse.ValidateInput("-3/- 2"));
 }
Exemple #5
0
 public void EnsureICanRemoveInappropriateWhiteSpace()
 {
     Parse aParse = new Parse();
     aParse.ParseInput("8          2     +23210 7     ");
     string expected = "82 + 232107";
     Assert.AreEqual(expected, aParse.Expression);
 }
Exemple #6
0
 public void EnsureICanCreateAnInstance()
 {
     Parse aParse = new Parse();
     Assert.IsNotNull(aParse);
 }
Exemple #7
0
 public void EnsureValidInputIsValidated()
 {
     Parse aParse = new Parse();
     Assert.AreEqual(true, aParse.ValidateInput("11 + 3"));
     Assert.AreEqual(true, aParse.ValidateInput("3 - 23"));
     Assert.AreEqual(true, aParse.ValidateInput("3 + -2"));
     Assert.AreEqual(true, aParse.ValidateInput("3 + +2"));
     Assert.AreEqual(true, aParse.ValidateInput("-13 + 3"));
     Assert.AreEqual(true, aParse.ValidateInput("3 - 20"));
     Assert.AreEqual(true, aParse.ValidateInput("-3 - 3"));
     Assert.AreEqual(true, aParse.ValidateInput("-3 - -3"));
     Assert.AreEqual(true, aParse.ValidateInput("1 * 3"));
     Assert.AreEqual(true, aParse.ValidateInput("3-2"));
     Assert.AreEqual(true, aParse.ValidateInput("3 + -2"));
     Assert.AreEqual(true, aParse.ValidateInput("3 + +2"));
     Assert.AreEqual(true, aParse.ValidateInput("-1 + 3"));
     Assert.AreEqual(true, aParse.ValidateInput("3 / 0"));
     Assert.AreEqual(true, aParse.ValidateInput("-3 - 3"));
     Assert.AreEqual(true, aParse.ValidateInput("-3 * -3"));
 }
Exemple #8
0
 public void EnsureInvalidInputThrowsAnError()
 {
     // Arrange
     Parse aParse = new Parse();
     string anInput = "1 + - 1";
     aParse.ParseInput(anInput);
 }