Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ PublishScripts/
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# and except a Unity project's Packages/, which is source: Unity's package manifest and its
# resolved lock file are both meant to be committed, and a NuGet restore folder never contains
# a file by either name.
!**/[Pp]ackages/manifest.json
!**/[Pp]ackages/packages-lock.json
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
Expand Down Expand Up @@ -651,3 +656,16 @@ Temporary Items

# ImGui.ini files
imgui.ini

# Game engine projects
#
# Godot: the import cache, and the mono/temp bin+obj a C# build writes.
.godot/

# Unity: .meta files are source, not the Visual Studio C++ build artifact that the `*.meta` rule
# further up targets. Unity generates one per asset and it carries the GUID that scenes, prefabs
# and serialized references point at, so ignoring them gives every clone fresh GUIDs and silently
# breaks those references - including for a plug-in whose .dll is itself a build output. This
# negation has to come after that rule to win, and is scoped to the asset tree so the Visual
# Studio artifact stays ignored everywhere else.
!**/[Aa]ssets/**/*.meta
28 changes: 28 additions & 0 deletions FuzzySearch.Test/FuzzyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,4 +860,32 @@ public void IntegrationTest_ScoresReflectMatchQuality()
}

#endregion

#region Repeated Letter Tests

private static int ScoreOf(string subject, string pattern)
{
Fuzzy.Contains(subject, pattern, out int score);
return score;
}

[TestMethod]
public void Score_RepeatedFirstLetter_ScoresBelowExactMatch()
{
Assert.IsGreaterThan(ScoreOf("aab", "ab"), ScoreOf("ab", "ab"), "A repeated letter should cost something.");
}

[TestMethod]
public void Score_ManyRepeatedLetters_ScoreBelowOneTrailingLetter()
{
Assert.IsGreaterThan(ScoreOf("aaaaaaaaaab", "ab"), ScoreOf("abx", "ab"), "Nine repeated letters should cost more than one trailing letter.");
}

[TestMethod]
public void Score_RepeatedLettersAfterSeparatorMatch_AreCharged()
{
Assert.IsGreaterThan(ScoreOf("a_bbbbbbbbbb", "ab"), ScoreOf("a_b", "ab"), "Repeated letters after a separator match should cost something.");
}

#endregion
}
6 changes: 6 additions & 0 deletions FuzzySearch/Fuzzy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
/// or the pattern is empty and the subject is not; otherwise, <c>false</c>.
/// </param>
/// <returns>A score representing the quality of the match. Higher scores indicate better matches.</returns>
internal static int CalculateScoreCore(ReadOnlySpan<char> subject, ReadOnlySpan<char> pattern, out bool wholePatternIsPresent)

Check warning on line 165 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.

Check warning on line 165 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.

Check warning on line 165 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.

Check warning on line 165 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.

Check warning on line 165 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.

Check warning on line 165 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.
{
if (pattern.IsEmpty)
{
Expand Down Expand Up @@ -255,6 +255,12 @@
bestLetterLength = strCharLength;
bestLetterScore = newScore;
}
else
{
// A rematch that loses to the current best letter is skipped too, so charge it like one.
// Otherwise repeats of a well-scoring letter are free and can tie an exact match.
score += unmatchedLetterPenalty;
}

prevMatched = true;
}
Expand Down Expand Up @@ -408,7 +414,7 @@

if (char.IsHighSurrogate(c) && i + 1 < value.Length && char.IsLowSurrogate(value[i + 1]))
{
i++;

Check warning on line 417 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.

Check warning on line 417 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.

Check warning on line 417 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.

Check warning on line 417 in FuzzySearch/Fuzzy.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.
continue;
}

Expand Down
Loading