Skip to content

Commit

Permalink
fix bugs and remove redundant candidates
Browse files Browse the repository at this point in the history
add boundary tests


put stuff in utils


hyngh


hmmmhg


workingish


refactor tests


use struct


remove some redundancy


refactor some tests
  • Loading branch information
vforteli committed Aug 27, 2022
1 parent cb016a6 commit 7f8c5df
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 173 deletions.
14 changes: 9 additions & 5 deletions FuzzySearchNet.Benchmark/BenchmarkFuzzySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ public class BenchmarkFuzzySearch
private const string term2 = "fooo--foo-----fo";
private const string text = "foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--foo-----fo--foo-f--fooo--";

[Benchmark]
public void SubstitutionOnlyBufferingShort() => FuzzySearch.FindSubstitutionsOnlyBuffering(term, text, 1);
//[Benchmark]
//public void SubstitutionOnlyBufferingShort() => FuzzySearch.FindSubstitutionsOnlyBuffering(term, text, 1);

[Benchmark]
public void SubstitutionOnlyBufferingLong() => FuzzySearch.FindSubstitutionsOnlyBuffering(term2, text, 1);
//[Benchmark]
//public void SubstitutionOnlyBufferingLong() => FuzzySearch.FindSubstitutionsOnlyBuffering(term2, text, 1);


//[Benchmark]
//public void SubstitutionOnlyBufferingLong3distance() => FuzzySearch.FindSubstitutionsOnlyBuffering(term2, text, 3);


[Benchmark]
public void SubstitutionOnlyBufferingLong3distance() => FuzzySearch.FindSubstitutionsOnlyBuffering(term2, text, 3);
public void LevenshteinLong() => FuzzySearch.FindBuffering(term2, text, 3);
}
28 changes: 28 additions & 0 deletions FuzzySearchNet.Tests/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace FuzzySearchNet.Tests;

internal class TestUtils
{
public static void AssertMatch(MatchResult match, int expectedStartIndex, int expectedEndIndex, string text, int? expectedDistance = null)
{
Assert.That(match.StartIndex, Is.EqualTo(expectedStartIndex));
Assert.That(match.EndIndex, Is.EqualTo(expectedEndIndex));
Assert.That(match.Match, Is.EqualTo(text[expectedStartIndex..expectedEndIndex]));

if (expectedDistance.HasValue)
{
Assert.That(match.Distance, Is.EqualTo(expectedDistance));
}
}

public static void AssertMatch(MatchResult match, int expectedStartIndex, string expectedMatch, int? expectedDistance = null)
{
Assert.That(match.StartIndex, Is.EqualTo(expectedStartIndex));
Assert.That(match.EndIndex, Is.EqualTo(expectedStartIndex + expectedMatch.Length));
Assert.That(match.Match, Is.EqualTo(expectedMatch));

if (expectedDistance.HasValue)
{
Assert.That(match.Distance, Is.EqualTo(expectedDistance));
}
}
}
2 changes: 1 addition & 1 deletion FuzzySearchNet.Tests/Tests/FuzzySearchExactMatchTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FuzzySearchNet.Tests.Tests;
namespace FuzzySearchNet.Tests;

public class FuzzySearchExactMatchTests
{
Expand Down
Loading

0 comments on commit 7f8c5df

Please sign in to comment.