Skip to content

Commit 1cd21c0

Browse files
committed
Fix testing
1 parent 2130599 commit 1cd21c0

File tree

1 file changed

+66
-31
lines changed

1 file changed

+66
-31
lines changed

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public List<int> GetPrecisionScores()
4040
Enum.GetValues(typeof(StringMatcher.SearchPrecisionScore))
4141
.Cast<StringMatcher.SearchPrecisionScore>()
4242
.ToList()
43-
.ForEach(x => listToReturn.Add((int)x));
43+
.ForEach(x => listToReturn.Add((int) x));
4444

4545
return listToReturn;
4646
}
@@ -92,7 +92,8 @@ public void WhenNotAllCharactersFoundInSearchString_ThenShouldReturnZeroScore(st
9292
[TestCase("cand")]
9393
[TestCase("cpywa")]
9494
[TestCase("ccs")]
95-
public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreaterThanPrecisionScoreResults(string searchTerm)
95+
public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreaterThanPrecisionScoreResults(
96+
string searchTerm)
9697
{
9798
var results = new List<Result>();
9899
var matcher = new StringMatcher();
@@ -108,9 +109,9 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
108109
foreach (var precisionScore in GetPrecisionScores())
109110
{
110111
var filteredResult = results.Where(result => result.Score >= precisionScore)
111-
.Select(result => result)
112-
.OrderByDescending(x => x.Score)
113-
.ToList();
112+
.Select(result => result)
113+
.OrderByDescending(x => x.Score)
114+
.ToList();
114115

115116
Debug.WriteLine("");
116117
Debug.WriteLine("###############################################");
@@ -119,6 +120,7 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
119120
{
120121
Debug.WriteLine("SCORE: " + item.Score.ToString() + ", FoundString: " + item.Title);
121122
}
123+
122124
Debug.WriteLine("###############################################");
123125
Debug.WriteLine("");
124126

@@ -128,11 +130,11 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
128130

129131
[TestCase(Chrome, Chrome, 157)]
130132
[TestCase(Chrome, LastIsChrome, 147)]
131-
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 25)]
133+
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 90)]
132134
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 21)]
133135
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
134-
[TestCase("sql", MicrosoftSqlServerManagementStudio, 110)]
135-
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 121)]//double spacing intended
136+
[TestCase("sql", MicrosoftSqlServerManagementStudio, 90)]
137+
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 121)] //double spacing intended
136138
public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
137139
string queryString, string compareString, int expectedScore)
138140
{
@@ -141,20 +143,20 @@ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
141143
var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore;
142144

143145
// Should
144-
Assert.AreEqual(expectedScore, rawScore,
146+
Assert.AreEqual(expectedScore, rawScore,
145147
$"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
146148
}
147149

148150
[TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
149151
[TestCase("chr", "Google Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
150152
[TestCase("chr", "Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
151-
[TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
152153
[TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
153154
[TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, false)]
154155
[TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.None, true)]
155-
[TestCase("ccs", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Low, true)]
156-
[TestCase("cand", "Candy Crush Saga from King",StringMatcher.SearchPrecisionScore.Regular, true)]
157-
[TestCase("cand", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
156+
[TestCase("ccs", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, true)]
157+
[TestCase("cand", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, true)]
158+
[TestCase("cand", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular,
159+
false)]
158160
public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
159161
string queryString,
160162
string compareString,
@@ -170,7 +172,8 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
170172
Debug.WriteLine("");
171173
Debug.WriteLine("###############################################");
172174
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
173-
Debug.WriteLine($"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int)expectedPrecisionScore})");
175+
Debug.WriteLine(
176+
$"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int) expectedPrecisionScore})");
174177
Debug.WriteLine("###############################################");
175178
Debug.WriteLine("");
176179

@@ -179,13 +182,15 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
179182
$"Query:{queryString}{Environment.NewLine} " +
180183
$"Compare:{compareString}{Environment.NewLine}" +
181184
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
182-
$"Precision Score: {(int)expectedPrecisionScore}");
185+
$"Precision Score: {(int) expectedPrecisionScore}");
183186
}
184187

185188
[TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", StringMatcher.SearchPrecisionScore.Regular, false)]
186189
[TestCase("term", "Windows Terminal (Preview)", StringMatcher.SearchPrecisionScore.Regular, true)]
187-
[TestCase("sql s managa", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
188-
[TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
190+
[TestCase("sql s managa", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular,
191+
false)]
192+
[TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular,
193+
false)]
189194
[TestCase("sql s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
190195
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
191196
[TestCase("sql", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
@@ -195,31 +200,38 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
195200
[TestCase("sql serv man", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
196201
[TestCase("sql studio", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
197202
[TestCase("mic", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
203+
[TestCase("mssms", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
204+
[TestCase("msms", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
198205
[TestCase("chr", "Shutdown", StringMatcher.SearchPrecisionScore.Regular, false)]
199-
[TestCase("mssms", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
200-
[TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, false)]
201-
[TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)]
206+
[TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).",
207+
StringMatcher.SearchPrecisionScore.Regular, false)]
208+
[TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).",
209+
StringMatcher.SearchPrecisionScore.Regular, true)]
202210
[TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
203211
[TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
204212
[TestCase("cod", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
205213
[TestCase("code", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
206214
[TestCase("codes", "Visual Studio Codes", StringMatcher.SearchPrecisionScore.Regular, true)]
215+
[TestCase("vsc", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
216+
[TestCase("vs", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
217+
[TestCase("vc", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
207218
public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
208219
string queryString,
209220
string compareString,
210221
StringMatcher.SearchPrecisionScore expectedPrecisionScore,
211222
bool expectedPrecisionResult)
212223
{
213224
// When
214-
var matcher = new StringMatcher { UserSettingSearchPrecision = expectedPrecisionScore };
225+
var matcher = new StringMatcher {UserSettingSearchPrecision = expectedPrecisionScore};
215226

216227
// Given
217228
var matchResult = matcher.FuzzyMatch(queryString, compareString);
218229

219230
Debug.WriteLine("");
220231
Debug.WriteLine("###############################################");
221232
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
222-
Debug.WriteLine($"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int)expectedPrecisionScore})");
233+
Debug.WriteLine(
234+
$"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int) expectedPrecisionScore})");
223235
Debug.WriteLine("###############################################");
224236
Debug.WriteLine("");
225237

@@ -228,7 +240,7 @@ public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
228240
$"Query:{queryString}{Environment.NewLine} " +
229241
$"Compare:{compareString}{Environment.NewLine}" +
230242
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
231-
$"Precision Score: {(int)expectedPrecisionScore}");
243+
$"Precision Score: {(int) expectedPrecisionScore}");
232244
}
233245

234246
[TestCase("man", "Task Manager", "eManual")]
@@ -238,7 +250,7 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
238250
string queryString, string compareString1, string compareString2)
239251
{
240252
// When
241-
var matcher = new StringMatcher { UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular };
253+
var matcher = new StringMatcher {UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular};
242254

243255
// Given
244256
var compareString1Result = matcher.FuzzyMatch(queryString, compareString1);
@@ -247,22 +259,24 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
247259
Debug.WriteLine("");
248260
Debug.WriteLine("###############################################");
249261
Debug.WriteLine($"QueryString: \"{queryString}\"{Environment.NewLine}");
250-
Debug.WriteLine($"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}");
251-
Debug.WriteLine($"CompareString2: \"{compareString2}\", Score: {compareString2Result.Score}{Environment.NewLine}");
262+
Debug.WriteLine(
263+
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}");
264+
Debug.WriteLine(
265+
$"CompareString2: \"{compareString2}\", Score: {compareString2Result.Score}{Environment.NewLine}");
252266
Debug.WriteLine("###############################################");
253267
Debug.WriteLine("");
254268

255269
// Should
256270
Assert.True(compareString1Result.Score > compareString2Result.Score,
257271
$"Query: \"{queryString}\"{Environment.NewLine} " +
258272
$"CompareString1: \"{compareString1}\", Score: {compareString1Result.Score}{Environment.NewLine}" +
259-
$"Should be greater than{ Environment.NewLine}" +
273+
$"Should be greater than{Environment.NewLine}" +
260274
$"CompareString2: \"{compareString2}\", Score: {compareString1Result.Score}{Environment.NewLine}");
261275
}
262276

263277
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
264278
public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
265-
string queryString, string firstName, string firstDescription, string firstExecutableName,
279+
string queryString, string firstName, string firstDescription, string firstExecutableName,
266280
string secondName, string secondDescription, string secondExecutableName)
267281
{
268282
// Act
@@ -275,15 +289,36 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
275289
var secondDescriptionMatch = matcher.FuzzyMatch(queryString, secondDescription).RawScore;
276290
var secondExecutableNameMatch = matcher.FuzzyMatch(queryString, secondExecutableName).RawScore;
277291

278-
var firstScore = new[] { firstNameMatch, firstDescriptionMatch, firstExecutableNameMatch }.Max();
279-
var secondScore = new[] { secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch }.Max();
292+
var firstScore = new[] {firstNameMatch, firstDescriptionMatch, firstExecutableNameMatch}.Max();
293+
var secondScore = new[] {secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch}.Max();
280294

281295
// Assert
282296
Assert.IsTrue(firstScore > secondScore,
283297
$"Query: \"{queryString}\"{Environment.NewLine} " +
284298
$"Name of first: \"{firstName}\", Final Score: {firstScore}{Environment.NewLine}" +
285-
$"Should be greater than{ Environment.NewLine}" +
299+
$"Should be greater than{Environment.NewLine}" +
286300
$"Name of second: \"{secondName}\", Final Score: {secondScore}{Environment.NewLine}");
287301
}
302+
303+
[TestCase("vsc","Visual Studio Code", 100)]
304+
[TestCase("jbr","JetBrain Rider",100)]
305+
[TestCase("jr","JetBrain Rider",90)]
306+
[TestCase("vs","Visual Studio",100)]
307+
[TestCase("vs","Visual Studio Preview",100)]
308+
[TestCase("vsp","Visual Studio Preview",100)]
309+
[TestCase("vsp","Visual Studio",0)]
310+
[TestCase("pc","Postman Canary",100)]
311+
312+
public void WhenGivenAnAcronymQuery_ShouldReturnAcronymScore(string queryString, string compareString,
313+
int desiredScore)
314+
{
315+
var matcher = new StringMatcher();
316+
var score = matcher.FuzzyMatch(queryString, compareString).Score;
317+
Assert.IsTrue(score == desiredScore,
318+
$@"Query: ""{queryString}""
319+
CompareString: ""{compareString}""
320+
Score: {score}
321+
Desired Score: {desiredScore}");
322+
}
288323
}
289324
}

0 commit comments

Comments
 (0)