mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 17:42:45 +08:00
[launcher] - Increase the score for Exact matches in the Name of the Application (#3213)
* Increase score for exact matches in the name * Added tests for exact matching * Used TestCase * variable for bonus score * Removed comment, variable is self explanatory
This commit is contained in:
parent
2e8602eb43
commit
f07d37ce0d
@ -223,6 +223,12 @@ namespace Wox.Infrastructure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (String.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
var bonusForExactMatch = 10;
|
||||||
|
score += bonusForExactMatch;
|
||||||
|
}
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,21 +122,24 @@ namespace Wox.Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(Chrome, Chrome, 137)]
|
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
|
||||||
[TestCase(Chrome, LastIsChrome, 83)]
|
public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(string queryString, string firstName, string firstDescription, string firstExecutableName, string secondName, string secondDescription, string secondExecutableName)
|
||||||
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 21)]
|
|
||||||
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 15)]
|
|
||||||
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
|
|
||||||
[TestCase("sql", MicrosoftSqlServerManagementStudio, 56)]
|
|
||||||
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 79)]//double spacing intended
|
|
||||||
public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryString, string compareString, int expectedScore)
|
|
||||||
{
|
{
|
||||||
// When, Given
|
// Act
|
||||||
var matcher = new StringMatcher();
|
var matcher = new StringMatcher();
|
||||||
var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore;
|
var firstNameMatch = matcher.FuzzyMatch(queryString, firstName).RawScore;
|
||||||
|
var firstDescriptionMatch = matcher.FuzzyMatch(queryString, firstDescription).RawScore;
|
||||||
|
var firstExecutableNameMatch = matcher.FuzzyMatch(queryString, firstExecutableName).RawScore;
|
||||||
|
|
||||||
// Should
|
var secondNameMatch = matcher.FuzzyMatch(queryString, secondName).RawScore;
|
||||||
Assert.AreEqual(expectedScore, rawScore, $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
|
var secondDescriptionMatch = matcher.FuzzyMatch(queryString, secondDescription).RawScore;
|
||||||
|
var secondExecutableNameMatch = matcher.FuzzyMatch(queryString, secondExecutableName).RawScore;
|
||||||
|
|
||||||
|
var firstScore = new[] { firstNameMatch, firstDescriptionMatch, firstExecutableNameMatch }.Max();
|
||||||
|
var secondScore = new[] { secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch }.Max();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsTrue(firstScore > secondScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
|
Loading…
Reference in New Issue
Block a user