Skip to content

Commit 062d629

Browse files
authored
add a case to FormulaChecker (#36)
* add a case to FormulaChecker * increment version
1 parent 3cb91fa commit 062d629

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

src/NoStringEvaluating.Tests/UnitTests/Data/CheckFormula.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@ public static IEnumerable<FormulaModel> Get()
4646
yield return CreateTestModelToCheck(";;;", false);
4747
yield return CreateTestModelToCheck(",", false);
4848
yield return CreateTestModelToCheck(",,", false);
49+
yield return CreateTestModelToCheck("?", false);
50+
yield return CreateTestModelToCheck("#", false);
51+
yield return CreateTestModelToCheck("?!!", false);
52+
yield return CreateTestModelToCheck(string.Empty, false);
53+
yield return CreateTestModelToCheck(" ", false);
4954
}
5055
}

src/NoStringEvaluating/Models/FormulaChecker/FormulaCheckerMistakeType.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ public enum FormulaCheckerMistakeType
3131
OperatorBetweenCurrentAndNextNode = 4,
3232

3333
/// <summary>
34-
/// Between prevNode and nextNode must be an operator, not node"
34+
/// Between prevNode and nextNode must be an operator, not node
3535
/// </summary>
3636
OperatorBetweenPrevAndNextNode = 5,
3737

3838
/// <summary>
39-
/// Before node must be a number or a closed bracket, not prevNodeName"
39+
/// Before node must be a number or a closed bracket, not prevNodeName
4040
/// </summary>
4141
NumberBeforeNode = 6,
4242

4343
/// <summary>
44-
/// After node must be a number or an opened bracket, not nextNodeName"
44+
/// After node must be a number or an opened bracket, not nextNodeName
4545
/// </summary>
4646
NumberAfterNode = 7,
4747

@@ -54,4 +54,9 @@ public enum FormulaCheckerMistakeType
5454
/// Two or more function chars in a sequence
5555
/// </summary>
5656
DoubledFunctionCharNodes = 9,
57+
58+
/// <summary>
59+
/// Empty or wrong formula
60+
/// </summary>
61+
EmptyOrWrongFormula = 10,
5762
}

src/NoStringEvaluating/NoStringEvaluating.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<Description>Fast low memory consuming mathematical evaluation without endless string parsing! Parses string formula once and uses its object sequence in each evaluation.</Description>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1010
<PackageIcon>logo.png</PackageIcon>
11-
<PackageReleaseNotes>.NET 8</PackageReleaseNotes>
11+
<PackageReleaseNotes>Add a new case to FormulaChecker (empty formula or meaningless chars)</PackageReleaseNotes>
1212
<PackageTags>Math, Mathematics, Mathematical-Expression, Expressions, Parser, Formula, Evaluator, Calculator, Solve, Calculation, Logic, Condition, Custom, Function, Math-Parser, Expression-Evaluator, Formula-Parser, Object-Pooling, NoString, RPN</PackageTags>
1313
<PackageProjectUrl>https://github.com/KovtunV/NoStringEvaluating</PackageProjectUrl>
1414
<RepositoryUrl>https://github.com/KovtunV/NoStringEvaluating</RepositoryUrl>
1515
<RepositoryType>git</RepositoryType>
16-
<Version>2.6.0</Version>
16+
<Version>2.6.1</Version>
1717
<PackageReadmeFile></PackageReadmeFile>
1818
</PropertyGroup>
1919

src/NoStringEvaluating/NoStringEvaluating.xml

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NoStringEvaluating/Services/Checking/FormulaChecker.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public CheckFormulaResult CheckSyntax(ReadOnlySpan<char> formula)
2929
var mistakes = new List<FormulaCheckerModel>();
3030
var nodes = _formulaParser.ParseWithoutRpn(formula);
3131

32+
CheckEmpty(mistakes, nodes);
3233
CheckBracketsCount(mistakes, nodes, 0, nodes.Count);
3334
CheckEmptyBrackets(mistakes, nodes, 0, nodes.Count);
3435
CheckNotOperatorableNodes(mistakes, nodes, 0, nodes.Count);
@@ -71,6 +72,15 @@ private static int GetNextIndex(List<BaseFormulaNode> nodes, int start, int end)
7172
return end;
7273
}
7374

75+
private static void CheckEmpty(List<FormulaCheckerModel> mistakes, List<BaseFormulaNode> nodes)
76+
{
77+
if (nodes.Count is 0)
78+
{
79+
var mistakeItem = CreateMistakeModel(FormulaCheckerMistakeType.EmptyOrWrongFormula, "Formula doesn't contain any meaningful characters");
80+
mistakes.Add(mistakeItem);
81+
}
82+
}
83+
7484
#region Function
7585

7686
private bool TryCheckFunction(List<FormulaCheckerModel> mistakes, List<BaseFormulaNode> nodes, ref int index)

0 commit comments

Comments
 (0)