Skip to content

Commit 54a458d

Browse files
committed
test: provide Settings via constructor for StringMatcher in tests
1 parent 99f2b3b commit 54a458d

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public StringMatcher(IAlphabet alphabet, Settings settings)
2929
public StringMatcher(IAlphabet alphabet)
3030
{
3131
_alphabet = alphabet;
32+
_settings = new Settings();
33+
UserSettingSearchPrecision = _settings.QuerySearchPrecision;
3234
}
3335

3436
public static MatchResult FuzzySearch(string query, string stringToCompare)

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NUnit.Framework;
66
using NUnit.Framework.Legacy;
77
using Flow.Launcher.Infrastructure;
8+
using Flow.Launcher.Infrastructure.UserSettings;
89
using Flow.Launcher.Plugin;
910
using Flow.Launcher.Plugin.SharedModels;
1011

@@ -62,7 +63,7 @@ public void MatchTest()
6263
};
6364

6465
var results = new List<Result>();
65-
var matcher = new StringMatcher(alphabet);
66+
var matcher = new StringMatcher(alphabet, new Settings());
6667
foreach (var str in sources)
6768
{
6869
results.Add(new Result
@@ -84,7 +85,7 @@ public void MatchTest()
8485
public void WhenNotAllCharactersFoundInSearchString_ThenShouldReturnZeroScore(string searchString)
8586
{
8687
var compareString = "Can have rum only in my glass";
87-
var matcher = new StringMatcher(alphabet);
88+
var matcher = new StringMatcher(alphabet, new Settings());
8889
var scoreResult = matcher.FuzzyMatch(searchString, compareString).RawScore;
8990

9091
ClassicAssert.True(scoreResult == 0);
@@ -100,7 +101,7 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
100101
string searchTerm)
101102
{
102103
var results = new List<Result>();
103-
var matcher = new StringMatcher(alphabet);
104+
var matcher = new StringMatcher(alphabet, new Settings());
104105
foreach (var str in GetSearchStrings())
105106
{
106107
results.Add(new Result
@@ -150,7 +151,7 @@ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
150151
string queryString, string compareString, int expectedScore)
151152
{
152153
// When, Given
153-
var matcher = new StringMatcher(alphabet) { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
154+
var matcher = new StringMatcher(alphabet, new Settings()) { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
154155
var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore;
155156

156157
// Should
@@ -184,7 +185,7 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
184185
bool expectedPrecisionResult)
185186
{
186187
// When
187-
var matcher = new StringMatcher(alphabet) { UserSettingSearchPrecision = expectedPrecisionScore };
188+
var matcher = new StringMatcher(alphabet, new Settings()) { UserSettingSearchPrecision = expectedPrecisionScore };
188189

189190
// Given
190191
var matchResult = matcher.FuzzyMatch(queryString, compareString);
@@ -235,7 +236,7 @@ public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
235236
bool expectedPrecisionResult)
236237
{
237238
// When
238-
var matcher = new StringMatcher(alphabet) { UserSettingSearchPrecision = expectedPrecisionScore };
239+
var matcher = new StringMatcher(alphabet, new Settings()) { UserSettingSearchPrecision = expectedPrecisionScore };
239240

240241
// Given
241242
var matchResult = matcher.FuzzyMatch(queryString, compareString);
@@ -263,7 +264,7 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
263264
string queryString, string compareString1, string compareString2)
264265
{
265266
// When
266-
var matcher = new StringMatcher(alphabet) { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
267+
var matcher = new StringMatcher(alphabet, new Settings()) { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
267268

268269
// Given
269270
var compareString1Result = matcher.FuzzyMatch(queryString, compareString1);
@@ -296,7 +297,7 @@ public void WhenGivenTwoStrings_Scoring_ShouldGiveMoreWeightToTheStringCloserToI
296297
string queryString, string compareString1, string compareString2)
297298
{
298299
// When
299-
var matcher = new StringMatcher(alphabet) { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
300+
var matcher = new StringMatcher(alphabet, new Settings()) { UserSettingSearchPrecision = SearchPrecisionScore.Regular };
300301

301302
// Given
302303
var compareString1Result = matcher.FuzzyMatch(queryString, compareString1);
@@ -326,7 +327,7 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
326327
string secondName, string secondDescription, string secondExecutableName)
327328
{
328329
// Act
329-
var matcher = new StringMatcher(alphabet);
330+
var matcher = new StringMatcher(alphabet, new Settings());
330331
var firstNameMatch = matcher.FuzzyMatch(queryString, firstName).RawScore;
331332
var firstDescriptionMatch = matcher.FuzzyMatch(queryString, firstDescription).RawScore;
332333
var firstExecutableNameMatch = matcher.FuzzyMatch(queryString, firstExecutableName).RawScore;
@@ -361,7 +362,7 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
361362
public void WhenGivenAnAcronymQuery_ShouldReturnAcronymScore(string queryString, string compareString,
362363
int desiredScore)
363364
{
364-
var matcher = new StringMatcher(alphabet);
365+
var matcher = new StringMatcher(alphabet, new Settings());
365366
var score = matcher.FuzzyMatch(queryString, compareString).Score;
366367
ClassicAssert.IsTrue(score == desiredScore,
367368
$@"Query: ""{queryString}""

0 commit comments

Comments
 (0)