@@ -77,7 +77,7 @@ public void MatchTest()
77
77
}
78
78
79
79
[ TestCase ( "Chrome" ) ]
80
- public void WhenGivenNotAllCharactersFoundInSearchStringThenShouldReturnZeroScore ( string searchString )
80
+ public void WhenNotAllCharactersFoundInSearchString_ThenShouldReturnZeroScore ( string searchString )
81
81
{
82
82
var compareString = "Can have rum only in my glass" ;
83
83
var matcher = new StringMatcher ( ) ;
@@ -92,7 +92,7 @@ public void WhenGivenNotAllCharactersFoundInSearchStringThenShouldReturnZeroScor
92
92
[ TestCase ( "cand" ) ]
93
93
[ TestCase ( "cpywa" ) ]
94
94
[ TestCase ( "ccs" ) ]
95
- public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterThanPrecisionScoreResults ( string searchTerm )
95
+ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreaterThanPrecisionScoreResults ( string searchTerm )
96
96
{
97
97
var results = new List < Result > ( ) ;
98
98
var matcher = new StringMatcher ( ) ;
@@ -107,7 +107,10 @@ public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterT
107
107
108
108
foreach ( var precisionScore in GetPrecisionScores ( ) )
109
109
{
110
- var filteredResult = results . Where ( result => result . Score >= precisionScore ) . Select ( result => result ) . OrderByDescending ( x => x . Score ) . ToList ( ) ;
110
+ var filteredResult = results . Where ( result => result . Score >= precisionScore )
111
+ . Select ( result => result )
112
+ . OrderByDescending ( x => x . Score )
113
+ . ToList ( ) ;
111
114
112
115
Debug . WriteLine ( "" ) ;
113
116
Debug . WriteLine ( "###############################################" ) ;
@@ -124,20 +127,22 @@ public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterT
124
127
}
125
128
126
129
[ TestCase ( Chrome , Chrome , 157 ) ]
127
- [ TestCase ( Chrome , LastIsChrome , 103 ) ]
128
- [ TestCase ( Chrome , HelpCureHopeRaiseOnMindEntityChrome , 21 ) ]
129
- [ TestCase ( Chrome , UninstallOrChangeProgramsOnYourComputer , 15 ) ]
130
+ [ TestCase ( Chrome , LastIsChrome , 147 ) ]
131
+ [ TestCase ( Chrome , HelpCureHopeRaiseOnMindEntityChrome , 25 ) ]
132
+ [ TestCase ( Chrome , UninstallOrChangeProgramsOnYourComputer , 21 ) ]
130
133
[ TestCase ( Chrome , CandyCrushSagaFromKing , 0 ) ]
131
- [ TestCase ( "sql" , MicrosoftSqlServerManagementStudio , 56 ) ]
132
- [ TestCase ( "sql manag" , MicrosoftSqlServerManagementStudio , 99 ) ] //double spacing intended
133
- public void WhenGivenQueryStringThenShouldReturnCurrentScoring ( string queryString , string compareString , int expectedScore )
134
+ [ TestCase ( "sql" , MicrosoftSqlServerManagementStudio , 110 ) ]
135
+ [ TestCase ( "sql manag" , MicrosoftSqlServerManagementStudio , 121 ) ] //double spacing intended
136
+ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring (
137
+ string queryString , string compareString , int expectedScore )
134
138
{
135
139
// When, Given
136
140
var matcher = new StringMatcher ( ) ;
137
141
var rawScore = matcher . FuzzyMatch ( queryString , compareString ) . RawScore ;
138
142
139
143
// Should
140
- Assert . AreEqual ( expectedScore , rawScore , $ "Expected score for compare string '{ compareString } ': { expectedScore } , Actual: { rawScore } ") ;
144
+ Assert . AreEqual ( expectedScore , rawScore ,
145
+ $ "Expected score for compare string '{ compareString } ': { expectedScore } , Actual: { rawScore } ") ;
141
146
}
142
147
143
148
[ TestCase ( "goo" , "Google Chrome" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
@@ -150,7 +155,7 @@ public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryStrin
150
155
[ TestCase ( "ccs" , "Candy Crush Saga from King" , StringMatcher . SearchPrecisionScore . Low , true ) ]
151
156
[ TestCase ( "cand" , "Candy Crush Saga from King" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
152
157
[ TestCase ( "cand" , "Help cure hope raise on mind entity Chrome" , StringMatcher . SearchPrecisionScore . Regular , false ) ]
153
- public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual (
158
+ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual (
154
159
string queryString ,
155
160
string compareString ,
156
161
StringMatcher . SearchPrecisionScore expectedPrecisionScore ,
@@ -185,8 +190,8 @@ public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(
185
190
[ TestCase ( "sql manag" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
186
191
[ TestCase ( "sql" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
187
192
[ TestCase ( "sql serv" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
188
- [ TestCase ( "sqlserv " , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , false ) ]
189
- [ TestCase ( "sql servman " , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , false ) ]
193
+ [ TestCase ( "servez " , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , false ) ]
194
+ [ TestCase ( "sql servz " , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , false ) ]
190
195
[ TestCase ( "sql serv man" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
191
196
[ TestCase ( "sql studio" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
192
197
[ TestCase ( "mic" , MicrosoftSqlServerManagementStudio , StringMatcher . SearchPrecisionScore . Regular , true ) ]
@@ -199,7 +204,7 @@ public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(
199
204
[ TestCase ( "cod" , VisualStudioCode , StringMatcher . SearchPrecisionScore . Regular , true ) ]
200
205
[ TestCase ( "code" , VisualStudioCode , StringMatcher . SearchPrecisionScore . Regular , true ) ]
201
206
[ TestCase ( "codes" , "Visual Studio Codes" , StringMatcher . SearchPrecisionScore . Regular , true ) ]
202
- public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings (
207
+ public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings (
203
208
string queryString ,
204
209
string compareString ,
205
210
StringMatcher . SearchPrecisionScore expectedPrecisionScore ,
@@ -225,5 +230,60 @@ public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
225
230
$ "Raw Score: { matchResult . RawScore } { Environment . NewLine } " +
226
231
$ "Precision Score: { ( int ) expectedPrecisionScore } ") ;
227
232
}
233
+
234
+ [ TestCase ( "man" , "Task Manager" , "eManual" ) ]
235
+ [ TestCase ( "term" , "Windows Terminal" , "Character Map" ) ]
236
+ [ TestCase ( "winterm" , "Windows Terminal" , "Cygwin64 Terminal" ) ]
237
+ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord (
238
+ string queryString , string compareString1 , string compareString2 )
239
+ {
240
+ // When
241
+ var matcher = new StringMatcher { UserSettingSearchPrecision = StringMatcher . SearchPrecisionScore . Regular } ;
242
+
243
+ // Given
244
+ var compareString1Result = matcher . FuzzyMatch ( queryString , compareString1 ) ;
245
+ var compareString2Result = matcher . FuzzyMatch ( queryString , compareString2 ) ;
246
+
247
+ Debug . WriteLine ( "" ) ;
248
+ Debug . WriteLine ( "###############################################" ) ;
249
+ 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 } ") ;
252
+ Debug . WriteLine ( "###############################################" ) ;
253
+ Debug . WriteLine ( "" ) ;
254
+
255
+ // Should
256
+ Assert . True ( compareString1Result . Score > compareString2Result . Score ,
257
+ $ "Query: \" { queryString } \" { Environment . NewLine } " +
258
+ $ "CompareString1: \" { compareString1 } \" , Score: { compareString1Result . Score } { Environment . NewLine } " +
259
+ $ "Should be greater than{ Environment . NewLine } " +
260
+ $ "CompareString2: \" { compareString2 } \" , Score: { compareString1Result . Score } { Environment . NewLine } ") ;
261
+ }
262
+
263
+ [ TestCase ( "vim" , "Vim" , "ignoreDescription" , "ignore.exe" , "Vim Diff" , "ignoreDescription" , "ignore.exe" ) ]
264
+ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore (
265
+ string queryString , string firstName , string firstDescription , string firstExecutableName ,
266
+ string secondName , string secondDescription , string secondExecutableName )
267
+ {
268
+ // Act
269
+ var matcher = new StringMatcher ( ) ;
270
+ var firstNameMatch = matcher . FuzzyMatch ( queryString , firstName ) . RawScore ;
271
+ var firstDescriptionMatch = matcher . FuzzyMatch ( queryString , firstDescription ) . RawScore ;
272
+ var firstExecutableNameMatch = matcher . FuzzyMatch ( queryString , firstExecutableName ) . RawScore ;
273
+
274
+ var secondNameMatch = matcher . FuzzyMatch ( queryString , secondName ) . RawScore ;
275
+ var secondDescriptionMatch = matcher . FuzzyMatch ( queryString , secondDescription ) . RawScore ;
276
+ var secondExecutableNameMatch = matcher . FuzzyMatch ( queryString , secondExecutableName ) . RawScore ;
277
+
278
+ var firstScore = new [ ] { firstNameMatch , firstDescriptionMatch , firstExecutableNameMatch } . Max ( ) ;
279
+ var secondScore = new [ ] { secondNameMatch , secondDescriptionMatch , secondExecutableNameMatch } . Max ( ) ;
280
+
281
+ // Assert
282
+ Assert . IsTrue ( firstScore > secondScore ,
283
+ $ "Query: \" { queryString } \" { Environment . NewLine } " +
284
+ $ "Name of first: \" { firstName } \" , Final Score: { firstScore } { Environment . NewLine } " +
285
+ $ "Should be greater than{ Environment . NewLine } " +
286
+ $ "Name of second: \" { secondName } \" , Final Score: { secondScore } { Environment . NewLine } ") ;
287
+ }
228
288
}
229
289
}
0 commit comments