Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/NoStringEvaluating.Tests/UnitTests/Data/CheckFormula.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public static IEnumerable<FormulaModel> Get()
yield return CreateTestModelToCheck(";;;", false);
yield return CreateTestModelToCheck(",", false);
yield return CreateTestModelToCheck(",,", false);
yield return CreateTestModelToCheck("?", false);
yield return CreateTestModelToCheck("#", false);
yield return CreateTestModelToCheck("?!!", false);
yield return CreateTestModelToCheck(string.Empty, false);
yield return CreateTestModelToCheck(" ", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public enum FormulaCheckerMistakeType
OperatorBetweenCurrentAndNextNode = 4,

/// <summary>
/// Between prevNode and nextNode must be an operator, not node"
/// Between prevNode and nextNode must be an operator, not node
/// </summary>
OperatorBetweenPrevAndNextNode = 5,

/// <summary>
/// Before node must be a number or a closed bracket, not prevNodeName"
/// Before node must be a number or a closed bracket, not prevNodeName
/// </summary>
NumberBeforeNode = 6,

/// <summary>
/// After node must be a number or an opened bracket, not nextNodeName"
/// After node must be a number or an opened bracket, not nextNodeName
/// </summary>
NumberAfterNode = 7,

Expand All @@ -54,4 +54,9 @@ public enum FormulaCheckerMistakeType
/// Two or more function chars in a sequence
/// </summary>
DoubledFunctionCharNodes = 9,

/// <summary>
/// Empty or wrong formula
/// </summary>
EmptyOrWrongFormula = 10,
}
4 changes: 2 additions & 2 deletions src/NoStringEvaluating/NoStringEvaluating.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<Description>Fast low memory consuming mathematical evaluation without endless string parsing! Parses string formula once and uses its object sequence in each evaluation.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>logo.png</PackageIcon>
<PackageReleaseNotes>.NET 8</PackageReleaseNotes>
<PackageReleaseNotes>Add a new case to FormulaChecker (empty formula or meaningless chars)</PackageReleaseNotes>
<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>
<PackageProjectUrl>https://github.com/KovtunV/NoStringEvaluating</PackageProjectUrl>
<RepositoryUrl>https://github.com/KovtunV/NoStringEvaluating</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<PackageReadmeFile></PackageReadmeFile>
</PropertyGroup>

Expand Down
11 changes: 8 additions & 3 deletions src/NoStringEvaluating/NoStringEvaluating.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/NoStringEvaluating/Services/Checking/FormulaChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public CheckFormulaResult CheckSyntax(ReadOnlySpan<char> formula)
var mistakes = new List<FormulaCheckerModel>();
var nodes = _formulaParser.ParseWithoutRpn(formula);

CheckEmpty(mistakes, nodes);
CheckBracketsCount(mistakes, nodes, 0, nodes.Count);
CheckEmptyBrackets(mistakes, nodes, 0, nodes.Count);
CheckNotOperatorableNodes(mistakes, nodes, 0, nodes.Count);
Expand Down Expand Up @@ -71,6 +72,15 @@ private static int GetNextIndex(List<BaseFormulaNode> nodes, int start, int end)
return end;
}

private static void CheckEmpty(List<FormulaCheckerModel> mistakes, List<BaseFormulaNode> nodes)
{
if (nodes.Count is 0)
{
var mistakeItem = CreateMistakeModel(FormulaCheckerMistakeType.EmptyOrWrongFormula, "Formula doesn't contain any meaningful characters");
mistakes.Add(mistakeItem);
}
}

#region Function

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