Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions src/F23.StringSimilarity/ShingleBased.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;

namespace F23.StringSimilarity
Expand All @@ -43,7 +42,7 @@ public abstract class ShingleBased
/// </summary>
private static readonly Regex SPACE_REG = new Regex("\\s+", RegexOptions.Compiled);

/// <summary>
/// <summary>
/// </summary>
/// <param name="k"></param>
/// <exception cref="ArgumentOutOfRangeException">If k is less than or equal to 0.</exception>
Expand All @@ -56,10 +55,10 @@ protected ShingleBased(int k)

this.k = k;
}

protected ShingleBased() : this(DEFAULT_K) { }

protected internal Dictionary<string, int> GetProfile(string s)
public Dictionary<string, int> GetProfile(string s)
{
var shingles = new Dictionary<string, int>();

Expand Down
53 changes: 28 additions & 25 deletions test/F23.StringSimilarity.Tests/CosineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,20 @@
* THE SOFTWARE.
*/

using System;
using System.CodeDom;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using F23.StringSimilarity.Tests.TestUtil;
using Xunit;
using Xunit.Abstractions;

namespace F23.StringSimilarity.Tests
{
[SuppressMessage("ReSharper", "ArgumentsStyleLiteral")]
[SuppressMessage("ReSharper", "ArgumentsStyleNamedExpression")]
public class CosineTest
public class CosineTest()
Comment thread
paulirwin marked this conversation as resolved.
Outdated
{
private readonly ITestOutputHelper _testOutputHelper;

public CosineTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

[Fact]
public void TestSimilarity()
{
Expand All @@ -55,8 +44,8 @@
var result = instance.Similarity("ABC", "ABCE");

Assert.Equal(
expected: 0.71,
actual: result,
expected: 0.71,
actual: result,
precision: 2 // 0.01
);

Expand All @@ -71,8 +60,8 @@
var result = instance.Similarity("AB", "ABCE");

Assert.Equal(
expected: 0.0,
actual: result,
expected: 0.0,
actual: result,
precision: 5 //0.00001
);
}
Expand All @@ -89,7 +78,7 @@
var result = instance.Similarity(string1, string2);

Assert.Equal(
expected: 0.8115,
expected: 0.8115,
actual: result,
precision: 3 //0.001
);
Expand Down Expand Up @@ -144,19 +133,33 @@
Assert.Equal(0.516185, cosine.Similarity(profile1, profile2), 6);
}

/// <summary>
/// StringSimilarity.NET specific. Ensures that GetProfile is public.
/// </summary>
/// <remarks>
/// https://github.com/feature23/StringSimilarity.NET/issues/21
/// </remarks>
[Fact]
public void GetProfile_IsPublic()
{
var cosine = new Cosine(k: 2);
var profile = cosine.GetProfile("test string");

Assert.NotNull(profile);
}

private static async Task<string> ReadResourceFileAsync(string file)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = $"{typeof(CosineTest).Namespace}.{file}";

using (var stream = assembly.GetManifestResourceStream(resourceName))
{
Debug.Assert(stream != null, "stream != null");
using (var reader = new StreamReader(stream))
{
return await reader.ReadToEndAsync();
}
}
await using var stream = assembly.GetManifestResourceStream(resourceName);

Check failure on line 156 in test/F23.StringSimilarity.Tests/CosineTest.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'Stream': type used in an asynchronous using statement must implement 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'?

Check failure on line 156 in test/F23.StringSimilarity.Tests/CosineTest.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'Stream': type used in an asynchronous using statement must implement 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'?

Debug.Assert(stream != null, "stream != null");

using var reader = new StreamReader(stream);

return await reader.ReadToEndAsync();
}
}
}
17 changes: 16 additions & 1 deletion test/F23.StringSimilarity.Tests/JaccardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;
using F23.StringSimilarity.Tests.TestUtil;
using Xunit;
Expand Down Expand Up @@ -59,5 +59,20 @@ public void TestDistance()

NullEmptyTests.TestDistance(instance);
}

/// <summary>
/// StringSimilarity.NET specific. Ensures that GetProfile is public.
/// </summary>
/// <remarks>
/// https://github.com/feature23/StringSimilarity.NET/issues/21
/// </remarks>
[Fact]
public void GetProfile_IsPublic()
{
var cosine = new Jaccard(k: 2);
var profile = cosine.GetProfile("test string");
Comment thread
paulirwin marked this conversation as resolved.
Outdated

Assert.NotNull(profile);
}
}
}
15 changes: 15 additions & 0 deletions test/F23.StringSimilarity.Tests/QGramTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,20 @@ public void TestDistance()

NullEmptyTests.AssertArgumentNullExceptions(instance);
}

/// <summary>
/// StringSimilarity.NET specific. Ensures that GetProfile is public.
/// </summary>
/// <remarks>
/// https://github.com/feature23/StringSimilarity.NET/issues/21
/// </remarks>
[Fact]
public void GetProfile_IsPublic()
{
var cosine = new QGram(k: 2);
var profile = cosine.GetProfile("test string");
Comment thread
paulirwin marked this conversation as resolved.
Outdated

Assert.NotNull(profile);
}
}
}
15 changes: 15 additions & 0 deletions test/F23.StringSimilarity.Tests/SorensenDiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,20 @@ public void TestDistance()
var instance = new SorensenDice();
NullEmptyTests.TestDistance(instance);
}

/// <summary>
/// StringSimilarity.NET specific. Ensures that GetProfile is public.
/// </summary>
/// <remarks>
/// https://github.com/feature23/StringSimilarity.NET/issues/21
/// </remarks>
[Fact]
public void GetProfile_IsPublic()
{
var cosine = new SorensenDice(k: 2);
var profile = cosine.GetProfile("test string");
Comment thread
paulirwin marked this conversation as resolved.
Outdated

Assert.NotNull(profile);
}
}
}
Loading