private static Expression DeserializedQueryExpressionAndValidate(InternalQuery internalRemoteQuery) { var deserializedQuery = internalRemoteQuery.SerializedExpression.ToExpression(); ExpressionValidator.Validate(deserializedQuery); return(deserializedQuery); }
public void UnitTestOverflowException() { // arrange Random rand = new Random(); string[] operators = { "+", "-", "*", "/" }; var expression = ""; for (int i = 0; i < 501; i++) { string randomOperator = operators[rand.Next(operators.Length)]; var randomNumber = rand.Next(-1000, 1000); expression += $"{randomNumber.ToString()}{randomOperator}-1"; } var validator = new ExpressionValidator(); // act var actualResult = validator.Validate(expression); // assert Assert.AreEqual(validator.ErrorTooLong, actualResult); }
public void ErrorIfIsNotEquality() { var input = "4*x + 5*y^3 -6*x"; var validator = new ExpressionValidator(); var result = validator.Validate(input); Assert.AreEqual(result.IsValid, false); }
private void ValidateExpressions(string expression, bool expectedResult) { var expressionValidator = new ExpressionValidator(); var result = expressionValidator.IsCorrect(expression); Assert.Equal(expectedResult, result); }
public void ErrorIfNullOrEmpty() { var validator = new ExpressionValidator(); var result1 = validator.Validate(null); Assert.AreEqual(result1.IsValid, false); var result2 = validator.Validate(string.Empty); Assert.AreEqual(result2.IsValid, false); }
/// <summary> /// Start the definition of a child instance by defining the concrete type /// </summary> /// <param name="pluggedType"></param> /// <returns></returns> public ConfiguredInstance IsConcreteType(Type pluggedType) { ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); var childInstance = new ConfiguredInstance(pluggedType); _instance.SetChild(_propertyName, childInstance); return(_instance); }
public void ErrorIfEmptyPartOfEquality() { var input = "4*x + 5*y^3 -6*x="; var validator = new ExpressionValidator(); var result = validator.Validate(input); Assert.AreEqual(result.IsValid, false); var input2 = "4*x + 5*y^3 -6*x="; var result2 = validator.Validate(input2); Assert.AreEqual(result2.IsValid, false); }
public void UnitTestEmptyExpressionException() { // arrange var expression = ""; var validator = new ExpressionValidator(); // act var actualResult = validator.Validate(expression); // assert Assert.AreEqual(validator.ErrorEmpty, actualResult); }
public void UnitTestExceededSymbolsException() { // arrange var expression = "(7+8*&(9-5))?"; var validator = new ExpressionValidator(); // act var actualResult = validator.Validate(expression); // assert Assert.AreEqual(validator.ErrorExceededSymbols, actualResult); }
public void UnitTestDifferentBracketsQuantityException() { // arrange var expression = "(7+8*(9-5)))"; var validator = new ExpressionValidator(); // act var actualResult = validator.Validate(expression); // assert Assert.AreEqual(validator.ErrorBracketsQuantity, actualResult); }
public void Validate_StringExpression_TrueOrFalse(string input, bool expected) { // Arrange var expression = new ExpressionValidator(); expression.Expression = input; // Act bool result = expression.Validate(); // Assert Assert.AreEqual(result, expected); }
public void ValidateString_MisplacedParenthesis1_ThrowError() { var myValidator = new ExpressionValidator(); var input3 = new List <string>(); input3.Add("1"); input3.Add("+"); input3.Add("3"); input3.Add("*"); input3.Add(")"); // <- misplaced paren is here var result3 = myValidator.Execute(input3); }
public void ValidateString_WrongNumberOfParenthesis_ThrowError() { var myValidator = new ExpressionValidator(); var input5 = new List <string>(); input5.Add("("); input5.Add("5"); input5.Add("+"); input5.Add("2"); input5.Add(")"); input5.Add(")"); // <- Bad var result5 = myValidator.Execute(input5); }
public void ValidateString_MisplacedParenthesis2_ThrowError() { var myValidator = new ExpressionValidator(); var input4 = new List <string>(); input4.Add("1"); input4.Add("+"); input4.Add("("); // <- misplaced paren is here input4.Add("*"); input4.Add("5"); var result4 = myValidator.Execute(input4); }
public void ValidateString_NormalExpression_PassValidation() { var myValidator = new ExpressionValidator(); var input1 = new List <string>(); input1.Add("1"); input1.Add("+"); input1.Add("3"); input1.Add("*"); input1.Add("5"); var result1 = new List <string>(myValidator.Execute(input1)); Assert.IsTrue(ShallowListEquality.Test(result1, input1)); }
public void ValidateString_ExpressionWithParenthesis_PassValidation() { var myValidator = new ExpressionValidator(); var input2 = new List <string>(); input2.Add("("); input2.Add("1"); input2.Add("*"); input2.Add("2"); input2.Add(")"); input2.Add("^"); input2.Add("5"); var result2 = new List <string>(myValidator.Execute(input2)); Assert.IsTrue(ShallowListEquality.Test(result2, input2)); }
protected void btn_onclick(object sender, EventArgs e) { ExpressionValidator v = new ExpressionValidator("a"); TreeNode <string> root = v.parse(); root.drawExpression(this); /*try * { * Console.WriteLine("Entered expression: " + v.getExpression()); * Console.WriteLine("Short expression: " + root.BuildShortExpression()); * Console.WriteLine("Long expression: " + root.BuildFullExpression()); * } * catch (NullReferenceException) * { * * }*/ }
public CreatePluginFamilyExpression <PLUGINTYPE> TheDefaultIsConcreteType <CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE { Type concreteType = typeof(CONCRETETYPE); ExpressionValidator.ValidatePluggabilityOf(concreteType).IntoPluginType(_pluginType); if (!PluginCache.GetPlugin(concreteType).CanBeAutoFilled) { throw new StructureMapException(231); } return(alterAndContinue(family => { ConfiguredInstance instance = new ConfiguredInstance(concreteType).WithName(concreteType.AssemblyQualifiedName); family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; })); }
public ActionResult ExpressionValidatorTask(string input) { ExpressionValidator validator = new ExpressionValidator(input); var failedRules = validator.GetFailedRules(); if (failedRules.Count == 0) { ViewBag.Result = "Yes"; } else { ViewBag.Result = "No"; foreach (var item in failedRules) { ModelState.AddModelError("input", item.Value.ErrorMessage); } } TempData["Input"] = input; return(View()); }
public void Setup() { _sut = new ExpressionValidator(); }
public void Validate() { var validator = new ExpressionValidator(Expression); validator.Validate(); }
public CompilerResults compileFromCompilationUnits(CompilerParameters parameters, CompilationUnitNode[] compilationUnits) { var results = new CompilerResults(); this.context = new CompilerContext(parameters, results); this.statementValidator = new StatementValidator(this.context); this.expressionValidator = new ExpressionValidator(this.context); this.statementValidator.ExpressionValidator = this.expressionValidator; this.expressionValidator.StatementValidator = this.statementValidator; this.reachabilityChecker = new ReachabilityChecker(context); this.assignmentChecker = new AssignmentChecker(context); this.bytecodeGenerator = new BytecodeGenerator(context); foreach (var cu in compilationUnits) { context.CompilationUnits.add(cu); } doCompile(); this.context = null; this.statementValidator = null; this.expressionValidator = null; this.reachabilityChecker = null; this.assignmentChecker = null; this.queryTranslator = null; this.documentationBuilder = null; if (parameters.ProgressTracker != null) { parameters.ProgressTracker.compilationFinished(); } return results; }
public CompilerResults compileFromFiles(CompilerParameters parameters, File[] files) { var results = new CompilerResults(); this.context = new CompilerContext(parameters, results); this.statementValidator = new StatementValidator(this.context); this.expressionValidator = new ExpressionValidator(this.context); this.statementValidator.ExpressionValidator = this.expressionValidator; this.expressionValidator.StatementValidator = this.statementValidator; this.reachabilityChecker = new ReachabilityChecker(context); this.assignmentChecker = new AssignmentChecker(context); this.bytecodeGenerator = new BytecodeGenerator(context); bool tragicError = false; var buffer = new char[4096]; var sb = new StringBuilder(); var parser = new Parser(); foreach (var file in files) { sb.setLength(0); InputStreamReader reader = null; try { reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")); int read; while ((read = reader.read(buffer)) != -1) { sb.append(buffer, 0, read); } var text = new char[sb.length()]; sb.getChars(0, sizeof(text), text, 0); if (sizeof(text) > 0) { if (text[sizeof(text) - 1] == '\u001a') { text[sizeof(text) - 1] = ' '; } } var preprocessor = new Preprocessor(results.codeErrorManager, text); preprocessor.Filename = file.getAbsolutePath(); preprocessor.Symbols.addAll(parameters.Symbols); var scanner = new PreprocessedTextScanner(results.codeErrorManager, preprocessor.preprocess()); scanner.Filename = file.getAbsolutePath(); var compilationUnit = parser.parseCompilationUnit(scanner); if (compilationUnit != null) { compilationUnit.Symbols = preprocessor.Symbols; context.CompilationUnits.add(compilationUnit); } } catch (CodeErrorException) { } catch (Exception e) { e.printStackTrace(); tragicError = true; break; } finally { if (reader != null) { try { reader.close(); } catch (IOException) { } } } } if (!tragicError) { if (!context.HasErrors) { if (parameters.ProgressTracker != null) { parameters.ProgressTracker.compilationStageFinished(CompilationStage.Parsing); } doCompile(); } } this.context = null; this.statementValidator = null; this.expressionValidator = null; this.reachabilityChecker = null; this.assignmentChecker = null; this.queryTranslator = null; this.documentationBuilder = null; if (parameters.ProgressTracker != null) { parameters.ProgressTracker.compilationFinished(); } return results; }
MethodResolver(ExpressionValidator expressionValidator, CompilerContext context) { this.expressionValidator = expressionValidator; this.context = context; }
public void ShouldValidateExpressionAsInValid() { // Assert.AreEqual(false, ExpressionValidator.Validate("{{[[(())]]}}(")); Assert.AreEqual(false, ExpressionValidator.Validate("}{")); }
public void ShouldValidateExpressionAsValid() { Assert.AreEqual(true, ExpressionValidator.Validate("{{[[(())]]}}")); }
public void RunDemo() { if (RunSortedListDemo) { SortedListWithArrayList list = new SortedListWithArrayList(); list.Add(56); list.Add(12); list.Add(98); list.Add(45); list.Add(7); list.Add(3); list.Add(1); list.Add(78); list.Add(4478); list.Add(-67); list.Add(-198); list.Add(6); list.Add(9); Printer.PrintToMedium(list.Print()); } if (RunSortedArrayDemo) { SortedListWithArray array = new SortedListWithArray(); array.Add(56); array.Add(12); array.Add(98); array.Add(45); array.Add(7); array.Add(3); array.Add(1); array.Add(78); array.Add(4478); array.Add(-67); array.Add(-198); array.Add(6); array.Add(9); Printer.PrintToMedium(array.Print()); } if (RunGraphDemo) { Graph graph = new Graph(); graph.Add(-5, 3); graph.Add(-2, 5); graph.Add(1, -4); graph.Add(4, 5); graph.Add(6, 4); Printer.PrintToMedium(graph.Print()); GraphTuple[] mins = graph.GetLocalMin(-5, 6); foreach (GraphTuple tuple in mins) { Printer.PrintToMedium(string.Format("({0},{1})", tuple.X, tuple.Y)); } } if (RunCustomIteratorDemo) { List <int> test1 = new List <int>() { 1, 2, 3, 4, 5, 6 }; List <int> test2 = new List <int>() { 7, 8, 9, 10, 11, 12 }; List <int> test3 = new List <int>() { 13, 14, 15, 16, 17, 18 }; List <int> test4 = new List <int>() { 19, 20, 21, 22, 23, 24 }; List <int> test5 = new List <int>() { 25, 26, 27, 28, 29, 30 }; CustomIteratorList iteratorList = new CustomIteratorList(); iteratorList.Add(test1); iteratorList.Add(test2); iteratorList.Add(test3); iteratorList.Add(test4); iteratorList.Add(test5); Printer.PrintToMedium(iteratorList.Print()); } if (RunPalindromeDemo) { string testString = "mom"; string testString2 = "12345654321"; string testString3 = "fafasdfasd"; string testString4 = "bob"; Printer.PrintToMedium(string.Format("{0}: {1}", testString, PalindromeChecker.IsMatch(testString))); Printer.PrintToMedium(string.Format("{0}: {1}", testString2, PalindromeChecker.IsMatch(testString2))); Printer.PrintToMedium(string.Format("{0}: {1}", testString3, PalindromeChecker.IsMatch(testString3))); Printer.PrintToMedium(string.Format("{0}: {1}", testString4, PalindromeChecker.IsMatch(testString4))); } if (RunWorldPopulationCounter) { int population = WorldPopulationCounter.EstimatePopulation(new DateTime(2099, 5, 23)); Printer.PrintToMedium(string.Format("Population on 5/23/2099 is: {0}", population)); } if (RunSetDemo) { MathSet set = new MathSet(); set.Add(10); set.Add(5); set.Add(5); set.Add(15); set.Add(89); set.Add(7); set.Add(98); Printer.PrintToMedium(set.Print()); } if (RunInsertionSort) { int[] array = new int[] { 1, 10, 56, -45, 89, 4, -976, 100, 45 }; InsertionSort.Sort(array); foreach (int i in array) { Console.WriteLine(i); } } if (RunNumberPairsDemo) { List <int> testList = new List <int>(); testList.Add(6); testList.Add(1); testList.Add(3); testList.Add(46); testList.Add(1); testList.Add(3); testList.Add(9); int numberOfPairs = NumberPairsChecker.NumberOfPairs(testList.ToArray(), 47); Printer.PrintToMedium(numberOfPairs.ToString()); } if (RunExpressionValidatorDemo) { string expression1 = "{[()]}"; //valid string expression2 = "{{{}}}"; //valid string expression3 = "([({})])"; //valid string expression4 = "(()))"; //valid string expression5 = "AAAA"; //invalid string expression6 = "]]]"; string expression7 = "}}}"; string expression8 = "}"; string expression9 = "{{{}}}]"; string expression10 = "{"; List <string> expressions = new List <string> { expression1, expression2, expression3, expression4, expression5, expression6, expression7, expression8, expression9, expression10 }; for (int i = 0; i < expressions.Count; i++) { Printer.PrintToMedium( $"Expression {i + 1} - {expressions[i]} is: {(ExpressionValidator.Validate(expressions[i]) ? "Valid" : "Invalid")}"); } } if (RunPathFinderDemo) { int[][] matrix1 = { new[] { 1, 0, 1, 0 }, new[] { 1, 1, 0, 0 }, new[] { 0, 1, 1, 0 }, new[] { 1, 1, 1, 1 }, }; int[][] matrix2 = { new[] { 1, 0, 1, 0 }, new[] { 1, 1, 1, 0 }, new[] { 0, 1, 0, 0 }, new[] { 1, 1, 1, 1 }, }; int[][] matrix3 = { new[] { 1, 1, 1, 1 }, new[] { 1, 1, 1, 1 }, new[] { 1, 1, 1, 1 }, new[] { 1, 1, 1, 1 }, }; List <Tuple <int, int> > path = PathFinder.FindPath(matrix1); Printer.PrintToMedium($"Path for Matrix 1 is"); foreach (Tuple <int, int> tuple in path) { Printer.PrintToMedium($"({tuple.Item1}, {tuple.Item2})"); } path = PathFinder.FindPath(matrix2); Printer.PrintToMedium($"Path for Matrix 2 is"); foreach (Tuple <int, int> tuple in path) { Printer.PrintToMedium($"({tuple.Item1}, {tuple.Item2})"); } path = PathFinder.FindPath(matrix3); Printer.PrintToMedium($"Path for Matrix 3 is"); foreach (Tuple <int, int> tuple in path) { Printer.PrintToMedium($"({tuple.Item1}, {tuple.Item2})"); } } }