|
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | 24 |
|
| 25 | +using System; |
25 | 26 | using System.CodeDom; |
26 | 27 | using System.Diagnostics; |
27 | 28 | using System.Diagnostics.CodeAnalysis; |
| 29 | +using System.Globalization; |
28 | 30 | using System.IO; |
29 | 31 | using System.Reflection; |
30 | 32 | using System.Threading.Tasks; |
31 | 33 | using F23.StringSimilarity.Tests.TestUtil; |
32 | 34 | using Xunit; |
| 35 | +using Xunit.Abstractions; |
33 | 36 |
|
34 | 37 | namespace F23.StringSimilarity.Tests |
35 | 38 | { |
36 | 39 | [SuppressMessage("ReSharper", "ArgumentsStyleLiteral")] |
37 | 40 | [SuppressMessage("ReSharper", "ArgumentsStyleNamedExpression")] |
38 | 41 | public class CosineTest |
39 | 42 | { |
| 43 | + private readonly ITestOutputHelper _testOutputHelper; |
| 44 | + |
| 45 | + public CosineTest(ITestOutputHelper testOutputHelper) |
| 46 | + { |
| 47 | + _testOutputHelper = testOutputHelper; |
| 48 | + } |
| 49 | + |
40 | 50 | [Fact] |
41 | 51 | public void TestSimilarity() |
42 | 52 | { |
@@ -94,6 +104,23 @@ public void TestDistance() |
94 | 104 | // TODO: regular (non-null/empty) distance tests |
95 | 105 | } |
96 | 106 |
|
| 107 | + [Fact] |
| 108 | + public void DocumentationExampleTest() |
| 109 | + { |
| 110 | + string s1 = "My first string"; |
| 111 | + string s2 = "My other string..."; |
| 112 | + |
| 113 | + // Let's work with sequences of 2 characters... |
| 114 | + var cosine = new Cosine(2); |
| 115 | + |
| 116 | + // For cosine similarity I need the profile of strings |
| 117 | + var profile1 = cosine.GetProfile(s1); |
| 118 | + var profile2 = cosine.GetProfile(s2); |
| 119 | + |
| 120 | + // Prints 0.516185 |
| 121 | + Assert.Equal(0.516185, cosine.Similarity(profile1, profile2), 6); |
| 122 | + } |
| 123 | + |
97 | 124 | private static async Task<string> ReadResourceFileAsync(string file) |
98 | 125 | { |
99 | 126 | var assembly = Assembly.GetExecutingAssembly(); |
|
0 commit comments