@@ -40,7 +40,7 @@ public List<int> GetPrecisionScores()
40
40
Enum . GetValues ( typeof ( StringMatcher . SearchPrecisionScore ) )
41
41
. Cast < StringMatcher . SearchPrecisionScore > ( )
42
42
. ToList ( )
43
- . ForEach ( x => listToReturn . Add ( ( int ) x ) ) ;
43
+ . ForEach ( x => listToReturn . Add ( ( int ) x ) ) ;
44
44
45
45
return listToReturn ;
46
46
}
@@ -92,7 +92,8 @@ public void WhenNotAllCharactersFoundInSearchString_ThenShouldReturnZeroScore(st
92
92
[ TestCase ( "cand" ) ]
93
93
[ TestCase ( "cpywa" ) ]
94
94
[ TestCase ( "ccs" ) ]
95
- public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreaterThanPrecisionScoreResults ( string searchTerm )
95
+ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreaterThanPrecisionScoreResults (
96
+ string searchTerm )
96
97
{
97
98
var results = new List < Result > ( ) ;
98
99
var matcher = new StringMatcher ( ) ;
@@ -108,9 +109,9 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
108
109
foreach ( var precisionScore in GetPrecisionScores ( ) )
109
110
{
110
111
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 ( ) ;
114
115
115
116
Debug . WriteLine ( "" ) ;
116
117
Debug . WriteLine ( "###############################################" ) ;
@@ -119,6 +120,7 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
119
120
{
120
121
Debug . WriteLine ( "SCORE: " + item . Score . ToString ( ) + ", FoundString: " + item . Title ) ;
121
122
}
123
+
122
124
Debug . WriteLine ( "###############################################" ) ;
123
125
Debug . WriteLine ( "" ) ;
124
126
@@ -128,11 +130,11 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
128
130
129
131
[ TestCase ( Chrome , Chrome , 157 ) ]
130
132
[ TestCase ( Chrome , LastIsChrome , 147 ) ]
131
- [ TestCase ( Chrome , HelpCureHopeRaiseOnMindEntityChrome , 25 ) ]
133
+ [ TestCase ( Chrome , HelpCureHopeRaiseOnMindEntityChrome , 90 ) ]
132
134
[ TestCase ( Chrome , UninstallOrChangeProgramsOnYourComputer , 21 ) ]
133
135
[ 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
136
138
public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring (
137
139
string queryString , string compareString , int expectedScore )
138
140
{
@@ -141,20 +143,20 @@ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
141
143
var rawScore = matcher . FuzzyMatch ( queryString , compareString ) . RawScore ;
142
144
143
145
// Should
144
- Assert . AreEqual ( expectedScore , rawScore ,
146
+ Assert . AreEqual ( expectedScore , rawScore ,
145
147
$ "Expected score for compare string '{ compareString } ': { expectedScore } , Actual: { rawScore } ") ;
146
148
}
147
149
148
150
[ TestCase ( "goo" , "Google Chrome" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
149
151
[ TestCase ( "chr" , "Google Chrome" , StringMatcher . SearchPrecisionScore . Low , true ) ]
150
152
[ TestCase ( "chr" , "Chrome" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
151
- [ TestCase ( "chr" , "Help cure hope raise on mind entity Chrome" , StringMatcher . SearchPrecisionScore . Regular , false ) ]
152
153
[ TestCase ( "chr" , "Help cure hope raise on mind entity Chrome" , StringMatcher . SearchPrecisionScore . Low , true ) ]
153
154
[ TestCase ( "chr" , "Candy Crush Saga from King" , StringMatcher . SearchPrecisionScore . Regular , false ) ]
154
155
[ 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 ) ]
158
160
public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual (
159
161
string queryString ,
160
162
string compareString ,
@@ -170,7 +172,8 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
170
172
Debug . WriteLine ( "" ) ;
171
173
Debug . WriteLine ( "###############################################" ) ;
172
174
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 } )") ;
174
177
Debug . WriteLine ( "###############################################" ) ;
175
178
Debug . WriteLine ( "" ) ;
176
179
@@ -179,13 +182,15 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
179
182
$ "Query:{ queryString } { Environment . NewLine } " +
180
183
$ "Compare:{ compareString } { Environment . NewLine } " +
181
184
$ "Raw Score: { matchResult . RawScore } { Environment . NewLine } " +
182
- $ "Precision Score: { ( int ) expectedPrecisionScore } ") ;
185
+ $ "Precision Score: { ( int ) expectedPrecisionScore } ") ;
183
186
}
184
187
185
188
[ TestCase ( "exce" , "OverLeaf-Latex: An online LaTeX editor" , StringMatcher . SearchPrecisionScore . Regular , false ) ]
186
189
[ 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 ) ]
189
194
[ TestCase ( "sql s manag" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
190
195
[ TestCase ( "sql manag" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
191
196
[ TestCase ( "sql" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
@@ -195,31 +200,38 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
195
200
[ TestCase ( "sql serv man" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
196
201
[ TestCase ( "sql studio" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
197
202
[ TestCase ( "mic" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
203
+ [ TestCase ( "mssms" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
204
+ [ TestCase ( "msms" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
198
205
[ 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 ) ]
202
210
[ TestCase ( "a test" , "This is a test" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
203
211
[ TestCase ( "test" , "This is a test" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
204
212
[ TestCase ( "cod" , VisualStudioCode , StringMatcher . SearchPrecisionScore . Regular , true ) ]
205
213
[ TestCase ( "code" , VisualStudioCode , StringMatcher . SearchPrecisionScore . Regular , true ) ]
206
214
[ 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 ) ]
207
218
public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings (
208
219
string queryString ,
209
220
string compareString ,
210
221
StringMatcher . SearchPrecisionScore expectedPrecisionScore ,
211
222
bool expectedPrecisionResult )
212
223
{
213
224
// When
214
- var matcher = new StringMatcher { UserSettingSearchPrecision = expectedPrecisionScore } ;
225
+ var matcher = new StringMatcher { UserSettingSearchPrecision = expectedPrecisionScore } ;
215
226
216
227
// Given
217
228
var matchResult = matcher . FuzzyMatch ( queryString , compareString ) ;
218
229
219
230
Debug . WriteLine ( "" ) ;
220
231
Debug . WriteLine ( "###############################################" ) ;
221
232
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 } )") ;
223
235
Debug . WriteLine ( "###############################################" ) ;
224
236
Debug . WriteLine ( "" ) ;
225
237
@@ -228,7 +240,7 @@ public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
228
240
$ "Query:{ queryString } { Environment . NewLine } " +
229
241
$ "Compare:{ compareString } { Environment . NewLine } " +
230
242
$ "Raw Score: { matchResult . RawScore } { Environment . NewLine } " +
231
- $ "Precision Score: { ( int ) expectedPrecisionScore } ") ;
243
+ $ "Precision Score: { ( int ) expectedPrecisionScore } ") ;
232
244
}
233
245
234
246
[ TestCase ( "man" , "Task Manager" , "eManual" ) ]
@@ -238,7 +250,7 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
238
250
string queryString , string compareString1 , string compareString2 )
239
251
{
240
252
// When
241
- var matcher = new StringMatcher { UserSettingSearchPrecision = StringMatcher . SearchPrecisionScore . Regular } ;
253
+ var matcher = new StringMatcher { UserSettingSearchPrecision = StringMatcher . SearchPrecisionScore . Regular } ;
242
254
243
255
// Given
244
256
var compareString1Result = matcher . FuzzyMatch ( queryString , compareString1 ) ;
@@ -247,22 +259,24 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
247
259
Debug . WriteLine ( "" ) ;
248
260
Debug . WriteLine ( "###############################################" ) ;
249
261
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 } ") ;
252
266
Debug . WriteLine ( "###############################################" ) ;
253
267
Debug . WriteLine ( "" ) ;
254
268
255
269
// Should
256
270
Assert . True ( compareString1Result . Score > compareString2Result . Score ,
257
271
$ "Query: \" { queryString } \" { Environment . NewLine } " +
258
272
$ "CompareString1: \" { compareString1 } \" , Score: { compareString1Result . Score } { Environment . NewLine } " +
259
- $ "Should be greater than{ Environment . NewLine } " +
273
+ $ "Should be greater than{ Environment . NewLine } " +
260
274
$ "CompareString2: \" { compareString2 } \" , Score: { compareString1Result . Score } { Environment . NewLine } ") ;
261
275
}
262
276
263
277
[ TestCase ( "vim" , "Vim" , "ignoreDescription" , "ignore.exe" , "Vim Diff" , "ignoreDescription" , "ignore.exe" ) ]
264
278
public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore (
265
- string queryString , string firstName , string firstDescription , string firstExecutableName ,
279
+ string queryString , string firstName , string firstDescription , string firstExecutableName ,
266
280
string secondName , string secondDescription , string secondExecutableName )
267
281
{
268
282
// Act
@@ -275,15 +289,36 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
275
289
var secondDescriptionMatch = matcher . FuzzyMatch ( queryString , secondDescription ) . RawScore ;
276
290
var secondExecutableNameMatch = matcher . FuzzyMatch ( queryString , secondExecutableName ) . RawScore ;
277
291
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 ( ) ;
280
294
281
295
// Assert
282
296
Assert . IsTrue ( firstScore > secondScore ,
283
297
$ "Query: \" { queryString } \" { Environment . NewLine } " +
284
298
$ "Name of first: \" { firstName } \" , Final Score: { firstScore } { Environment . NewLine } " +
285
- $ "Should be greater than{ Environment . NewLine } " +
299
+ $ "Should be greater than{ Environment . NewLine } " +
286
300
$ "Name of second: \" { secondName } \" , Final Score: { secondScore } { Environment . NewLine } ") ;
287
301
}
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
+ }
288
323
}
289
324
}
0 commit comments