@@ -21,6 +21,8 @@ public class FuzzyMatcherTest
21
21
private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio" ;
22
22
private const string VisualStudioCode = "Visual Studio Code" ;
23
23
24
+ private readonly IAlphabet alphabet = null ;
25
+
24
26
public List < string > GetSearchStrings ( )
25
27
=> new List < string >
26
28
{
@@ -59,7 +61,7 @@ public void MatchTest()
59
61
} ;
60
62
61
63
var results = new List < Result > ( ) ;
62
- var matcher = new StringMatcher ( ) ;
64
+ var matcher = new StringMatcher ( alphabet ) ;
63
65
foreach ( var str in sources )
64
66
{
65
67
results . Add ( new Result
@@ -81,7 +83,7 @@ public void MatchTest()
81
83
public void WhenNotAllCharactersFoundInSearchString_ThenShouldReturnZeroScore ( string searchString )
82
84
{
83
85
var compareString = "Can have rum only in my glass" ;
84
- var matcher = new StringMatcher ( ) ;
86
+ var matcher = new StringMatcher ( alphabet ) ;
85
87
var scoreResult = matcher . FuzzyMatch ( searchString , compareString ) . RawScore ;
86
88
87
89
Assert . True ( scoreResult == 0 ) ;
@@ -97,7 +99,7 @@ public void GivenQueryString_WhenAppliedPrecisionFiltering_ThenShouldReturnGreat
97
99
string searchTerm )
98
100
{
99
101
var results = new List < Result > ( ) ;
100
- var matcher = new StringMatcher ( ) ;
102
+ var matcher = new StringMatcher ( alphabet ) ;
101
103
foreach ( var str in GetSearchStrings ( ) )
102
104
{
103
105
results . Add ( new Result
@@ -147,7 +149,7 @@ public void WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring(
147
149
string queryString , string compareString , int expectedScore )
148
150
{
149
151
// When, Given
150
- var matcher = new StringMatcher { UserSettingSearchPrecision = SearchPrecisionScore . Regular } ;
152
+ var matcher = new StringMatcher ( alphabet ) { UserSettingSearchPrecision = SearchPrecisionScore . Regular } ;
151
153
var rawScore = matcher . FuzzyMatch ( queryString , compareString ) . RawScore ;
152
154
153
155
// Should
@@ -181,7 +183,7 @@ public void WhenGivenDesiredPrecision_ThenShouldReturn_AllResultsGreaterOrEqual(
181
183
bool expectedPrecisionResult )
182
184
{
183
185
// When
184
- var matcher = new StringMatcher { UserSettingSearchPrecision = expectedPrecisionScore } ;
186
+ var matcher = new StringMatcher ( alphabet ) { UserSettingSearchPrecision = expectedPrecisionScore } ;
185
187
186
188
// Given
187
189
var matchResult = matcher . FuzzyMatch ( queryString , compareString ) ;
@@ -232,7 +234,7 @@ public void WhenGivenQuery_ShouldReturnResults_ContainingAllQuerySubstrings(
232
234
bool expectedPrecisionResult )
233
235
{
234
236
// When
235
- var matcher = new StringMatcher { UserSettingSearchPrecision = expectedPrecisionScore } ;
237
+ var matcher = new StringMatcher ( alphabet ) { UserSettingSearchPrecision = expectedPrecisionScore } ;
236
238
237
239
// Given
238
240
var matchResult = matcher . FuzzyMatch ( queryString , compareString ) ;
@@ -260,7 +262,7 @@ public void WhenGivenAQuery_Scoring_ShouldGiveMoreWeightToStartOfNewWord(
260
262
string queryString , string compareString1 , string compareString2 )
261
263
{
262
264
// When
263
- var matcher = new StringMatcher { UserSettingSearchPrecision = SearchPrecisionScore . Regular } ;
265
+ var matcher = new StringMatcher ( alphabet ) { UserSettingSearchPrecision = SearchPrecisionScore . Regular } ;
264
266
265
267
// Given
266
268
var compareString1Result = matcher . FuzzyMatch ( queryString , compareString1 ) ;
@@ -293,7 +295,7 @@ public void WhenGivenTwoStrings_Scoring_ShouldGiveMoreWeightToTheStringCloserToI
293
295
string queryString , string compareString1 , string compareString2 )
294
296
{
295
297
// When
296
- var matcher = new StringMatcher { UserSettingSearchPrecision = SearchPrecisionScore . Regular } ;
298
+ var matcher = new StringMatcher ( alphabet ) { UserSettingSearchPrecision = SearchPrecisionScore . Regular } ;
297
299
298
300
// Given
299
301
var compareString1Result = matcher . FuzzyMatch ( queryString , compareString1 ) ;
@@ -323,7 +325,7 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
323
325
string secondName , string secondDescription , string secondExecutableName )
324
326
{
325
327
// Act
326
- var matcher = new StringMatcher ( ) ;
328
+ var matcher = new StringMatcher ( alphabet ) ;
327
329
var firstNameMatch = matcher . FuzzyMatch ( queryString , firstName ) . RawScore ;
328
330
var firstDescriptionMatch = matcher . FuzzyMatch ( queryString , firstDescription ) . RawScore ;
329
331
var firstExecutableNameMatch = matcher . FuzzyMatch ( queryString , firstExecutableName ) . RawScore ;
@@ -358,7 +360,7 @@ public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(
358
360
public void WhenGivenAnAcronymQuery_ShouldReturnAcronymScore ( string queryString , string compareString ,
359
361
int desiredScore )
360
362
{
361
- var matcher = new StringMatcher ( ) ;
363
+ var matcher = new StringMatcher ( alphabet ) ;
362
364
var score = matcher . FuzzyMatch ( queryString , compareString ) . Score ;
363
365
Assert . IsTrue ( score == desiredScore ,
364
366
$@ "Query: ""{ queryString } ""
0 commit comments