public void Validate_WhenInputISValid_ShouldReturnEmptyValidationResultList(string input) { // Arrange ExpressionsValidator classUnderTest = CreateClassUnderTest(); // Act IList <ValidationResult> result = classUnderTest.Validate(input); // Assert Assert.IsNotNull(result); Assert.IsEmpty(result); }
public void Validate_WhenInputIsEmptyOrIsSingleOperator_ShouldThrowValidationError(string input) { // Arrange ExpressionsValidator classUnderTest = CreateClassUnderTest(); // Act IList <ValidationResult> result = classUnderTest.Validate(input); // Assert Assert.IsNotNull(result); Assert.IsNotEmpty(result); Assert.AreEqual(1, result.Count); Assert.AreEqual("Input must contain at least one number", result[0].ErrorMessage); }
public void Validate_WhenInputContainsTwoOrMoreConsecutuveOperators_ShouldThrowValidationError(string input) { // Arrange ExpressionsValidator classUnderTest = CreateClassUnderTest(); // Act IList <ValidationResult> result = classUnderTest.Validate(input); // Assert Assert.IsNotNull(result); Assert.IsNotEmpty(result); Assert.AreEqual(1, result.Count); Assert.AreEqual("Input contains two or more consecutive operators", result[0].ErrorMessage); }
public void Validate_WhenInputIsEmptyOrContainsInvalidOperators_ShouldThrowValidationError(string input) { // Arrange ExpressionsValidator classUnderTest = CreateClassUnderTest(); // Act IList <ValidationResult> result = classUnderTest.Validate(input); // Assert Assert.IsNotNull(result); Assert.IsNotEmpty(result); Assert.AreEqual(1, result.Count); Assert.AreEqual("Input can only contain digits, empty spaces and any of the operators \"+\", \"-\", \"*\" and \"/\"", result[0].ErrorMessage); }
private static ICalculator <decimal> InitCalculator() { var formatter = new ExpressionFormatter(); // Список доступных операций var binaryOperations = new List <BinaryOperation <decimal> > { new BinaryOperation <decimal>("+", 10, (a, b) => a + b), new BinaryOperation <decimal>("-", 10, (a, b) => a - b), new BinaryOperation <decimal>("*", 21, (a, b) => a * b), new BinaryOperation <decimal>("/", 21, (a, b) => a / b) }; var validator = new ExpressionsValidator <decimal>(); var parser = new RPNParser <decimal>(binaryOperations); return(new Calculator <decimal>(parser, validator, formatter)); }
public void Validate_WhenInputContainsOnlyRepeatingOperators_ShouldThrowValidationErrors(string input) { // Arrange ExpressionsValidator classUnderTest = CreateClassUnderTest(); // Act IList <ValidationResult> result = classUnderTest.Validate(input); // Assert Assert.IsNotNull(result); Assert.IsNotEmpty(result); Assert.AreEqual(2, result.Count); ValidationResult firstValidationError = result[0]; Assert.AreEqual("Input must contain at least one number", firstValidationError.ErrorMessage); ValidationResult secondValidationError = result[1]; Assert.AreEqual("Input contains two or more consecutive operators", secondValidationError.ErrorMessage); }