diff --git a/src/F23.StringSimilarity/ShingleBased.cs b/src/F23.StringSimilarity/ShingleBased.cs index 2b2e70f..bc354d4 100644 --- a/src/F23.StringSimilarity/ShingleBased.cs +++ b/src/F23.StringSimilarity/ShingleBased.cs @@ -24,7 +24,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Text.RegularExpressions; namespace F23.StringSimilarity @@ -43,7 +42,7 @@ public abstract class ShingleBased /// private static readonly Regex SPACE_REG = new Regex("\\s+", RegexOptions.Compiled); - /// + /// /// /// /// If k is less than or equal to 0. @@ -56,10 +55,10 @@ protected ShingleBased(int k) this.k = k; } - + protected ShingleBased() : this(DEFAULT_K) { } - protected internal Dictionary GetProfile(string s) + public Dictionary GetProfile(string s) { var shingles = new Dictionary(); diff --git a/test/F23.StringSimilarity.Tests/CosineTest.cs b/test/F23.StringSimilarity.Tests/CosineTest.cs index b209382..2a4fcea 100644 --- a/test/F23.StringSimilarity.Tests/CosineTest.cs +++ b/test/F23.StringSimilarity.Tests/CosineTest.cs @@ -22,17 +22,13 @@ * 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 { @@ -40,13 +36,6 @@ namespace F23.StringSimilarity.Tests [SuppressMessage("ReSharper", "ArgumentsStyleNamedExpression")] public class CosineTest { - private readonly ITestOutputHelper _testOutputHelper; - - public CosineTest(ITestOutputHelper testOutputHelper) - { - _testOutputHelper = testOutputHelper; - } - [Fact] public void TestSimilarity() { @@ -55,8 +44,8 @@ public void TestSimilarity() var result = instance.Similarity("ABC", "ABCE"); Assert.Equal( - expected: 0.71, - actual: result, + expected: 0.71, + actual: result, precision: 2 // 0.01 ); @@ -71,8 +60,8 @@ public void TestSmallString() var result = instance.Similarity("AB", "ABCE"); Assert.Equal( - expected: 0.0, - actual: result, + expected: 0.0, + actual: result, precision: 5 //0.00001 ); } @@ -89,7 +78,7 @@ public async Task TestLargeString() var result = instance.Similarity(string1, string2); Assert.Equal( - expected: 0.8115, + expected: 0.8115, actual: result, precision: 3 //0.001 ); @@ -144,19 +133,34 @@ public void DocumentationExampleTest() Assert.Equal(0.516185, cosine.Similarity(profile1, profile2), 6); } + /// + /// StringSimilarity.NET specific. Ensures that GetProfile is public. + /// + /// + /// https://github.com/feature23/StringSimilarity.NET/issues/21 + /// + [Fact] + public void GetProfile_IsPublic() + { + var cosine = new Cosine(k: 2); + var profile = cosine.GetProfile("test string"); + + Assert.NotNull(profile); + } + private static async Task 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(); - } - } + // ReSharper disable once UseAwaitUsing - not supported on netstandard2.0 + using var stream = assembly.GetManifestResourceStream(resourceName); + + Debug.Assert(stream != null, "stream != null"); + + using var reader = new StreamReader(stream); + + return await reader.ReadToEndAsync(); } } } diff --git a/test/F23.StringSimilarity.Tests/JaccardTest.cs b/test/F23.StringSimilarity.Tests/JaccardTest.cs index 10bb8d3..83dcf05 100644 --- a/test/F23.StringSimilarity.Tests/JaccardTest.cs +++ b/test/F23.StringSimilarity.Tests/JaccardTest.cs @@ -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; @@ -59,5 +59,20 @@ public void TestDistance() NullEmptyTests.TestDistance(instance); } + + /// + /// StringSimilarity.NET specific. Ensures that GetProfile is public. + /// + /// + /// https://github.com/feature23/StringSimilarity.NET/issues/21 + /// + [Fact] + public void GetProfile_IsPublic() + { + var jaccard = new Jaccard(k: 2); + var profile = jaccard.GetProfile("test string"); + + Assert.NotNull(profile); + } } } diff --git a/test/F23.StringSimilarity.Tests/QGramTest.cs b/test/F23.StringSimilarity.Tests/QGramTest.cs index a2f8569..de4e20f 100644 --- a/test/F23.StringSimilarity.Tests/QGramTest.cs +++ b/test/F23.StringSimilarity.Tests/QGramTest.cs @@ -63,5 +63,20 @@ public void TestDistance() NullEmptyTests.AssertArgumentNullExceptions(instance); } + + /// + /// StringSimilarity.NET specific. Ensures that GetProfile is public. + /// + /// + /// https://github.com/feature23/StringSimilarity.NET/issues/21 + /// + [Fact] + public void GetProfile_IsPublic() + { + var qgram = new QGram(k: 2); + var profile = qgram.GetProfile("test string"); + + Assert.NotNull(profile); + } } } diff --git a/test/F23.StringSimilarity.Tests/SorensenDiceTest.cs b/test/F23.StringSimilarity.Tests/SorensenDiceTest.cs index d190df7..c174466 100644 --- a/test/F23.StringSimilarity.Tests/SorensenDiceTest.cs +++ b/test/F23.StringSimilarity.Tests/SorensenDiceTest.cs @@ -58,5 +58,20 @@ public void TestDistance() var instance = new SorensenDice(); NullEmptyTests.TestDistance(instance); } + + /// + /// StringSimilarity.NET specific. Ensures that GetProfile is public. + /// + /// + /// https://github.com/feature23/StringSimilarity.NET/issues/21 + /// + [Fact] + public void GetProfile_IsPublic() + { + var dice = new SorensenDice(k: 2); + var profile = dice.GetProfile("test string"); + + Assert.NotNull(profile); + } } }