Add unit tests for checking substrings

checking if all substrings contained in compareString
This commit is contained in:
Jeremy Wu 2020-01-07 07:55:02 +11:00
parent 0093838a75
commit 24cc5dbaa0
2 changed files with 23 additions and 1 deletions

View file

@ -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
}
}
/// <summary>
/// Indicates if all query's substrings are contained in the string to compare
/// </summary>
public bool AllSubstringsContainedInCompareString { get; set; }
/// <summary>
/// Matched data to highlight.
/// </summary>

View file

@ -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);
}
}
}