From 24cc5dbaa0930e4ea6176c99410175745e566c57 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 7 Jan 2020 07:55:02 +1100 Subject: [PATCH] Add unit tests for checking substrings checking if all substrings contained in compareString --- Wox.Infrastructure/StringMatcher.cs | 8 +++++++- Wox.Test/FuzzyMatcherTest.cs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Wox.Infrastructure/StringMatcher.cs b/Wox.Infrastructure/StringMatcher.cs index 1868eee6e1..a5162c2813 100644 --- a/Wox.Infrastructure/StringMatcher.cs +++ b/Wox.Infrastructure/StringMatcher.cs @@ -147,7 +147,8 @@ namespace Wox.Infrastructure { Success = true, MatchData = indexList, - RawScore = Math.Max(score, pinyinScore) + RawScore = Math.Max(score, pinyinScore), + AllSubstringsContainedInCompareString = allSubstringsContainedInCompareString }; return result; @@ -288,6 +289,11 @@ namespace Wox.Infrastructure } } + /// + /// Indicates if all query's substrings are contained in the string to compare + /// + public bool AllSubstringsContainedInCompareString { get; set; } + /// /// Matched data to highlight. /// diff --git a/Wox.Test/FuzzyMatcherTest.cs b/Wox.Test/FuzzyMatcherTest.cs index 7eb16c8a0c..660a8ff96d 100644 --- a/Wox.Test/FuzzyMatcherTest.cs +++ b/Wox.Test/FuzzyMatcherTest.cs @@ -247,5 +247,21 @@ namespace Wox.Test $"Raw Score: {matchResult.RawScore}{Environment.NewLine}" + $"Precision Level: {expectedPrecisionString}={expectedPrecisionScore}"); } + + [TestCase("sql servman", MicrosoftSqlServerManagementStudio, false)] + [TestCase("sql serv man", MicrosoftSqlServerManagementStudio, true)] + [TestCase("sql", MicrosoftSqlServerManagementStudio, true)] + [TestCase("sqlserv", MicrosoftSqlServerManagementStudio, false)] + [TestCase("mssms", MicrosoftSqlServerManagementStudio, false)] + [TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", false)] + [TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", true)] + public void WhenGivenQueryShouldEvaluateTrueFalseIfCompareStringContainsAllSubstrings(string queryString, string compareString, bool expectedResult) + { + // When, Given + var matchResult = StringMatcher.FuzzySearch(queryString, compareString).AllSubstringsContainedInCompareString; + + // Should + Assert.AreEqual(matchResult, expectedResult); + } } } \ No newline at end of file