Skip to content

Commit ebb8966

Browse files
committed
Added unit test project
1 parent e8e2779 commit ebb8966

9 files changed

+157304
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ src/packages/
22
src/Skybrud.TextAnalysis/bin/
33
src/Skybrud.TextAnalysis/obj/
44
src/.vs/
5+
src/UnitTestProject1/bin/
6+
src/UnitTestProject1/obj/

src/Skybrud.TextAnalysis.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.29806.167
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skybrud.TextAnalysis", "Skybrud.TextAnalysis\Skybrud.TextAnalysis.csproj", "{1D28A1E8-826F-4A30-AF13-944A1365A5B1}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skybrud.TextAnalysis", "Skybrud.TextAnalysis\Skybrud.TextAnalysis.csproj", "{1D28A1E8-826F-4A30-AF13-944A1365A5B1}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject1", "UnitTestProject1\UnitTestProject1.csproj", "{DFAC6A0C-9955-4D5F-BC59-47D05A9A3370}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
1517
{1D28A1E8-826F-4A30-AF13-944A1365A5B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{1D28A1E8-826F-4A30-AF13-944A1365A5B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{1D28A1E8-826F-4A30-AF13-944A1365A5B1}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{DFAC6A0C-9955-4D5F-BC59-47D05A9A3370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{DFAC6A0C-9955-4D5F-BC59-47D05A9A3370}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{DFAC6A0C-9955-4D5F-BC59-47D05A9A3370}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{DFAC6A0C-9955-4D5F-BC59-47D05A9A3370}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Linq;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Skybrud.TextAnalysis.Hunspell;
5+
using Skybrud.TextAnalysis.Hunspell.Stem;
6+
using Skybrud.Essentials.Strings.Extensions;
7+
8+
namespace UnitTestProject1.Hunspell {
9+
10+
[TestClass]
11+
public class MorphTests {
12+
13+
[TestMethod]
14+
public void Hesten_Stem() {
15+
16+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
17+
18+
HunspellStemResult stem = analyzer.Stem("hesten").FirstOrDefault();
19+
20+
Assert.IsNotNull(stem);
21+
22+
string[] morph = analyzer.Morph(stem);
23+
24+
Assert.AreEqual(8, morph.Length);
25+
26+
Assert.AreEqual("hest", morph[0]);
27+
Assert.AreEqual("hestes", morph[1]);
28+
Assert.AreEqual("hestene", morph[2]);
29+
Assert.AreEqual("heste", morph[3]);
30+
Assert.AreEqual("hestenes", morph[4]);
31+
Assert.AreEqual("hesten", morph[5]);
32+
Assert.AreEqual("hestens", morph[6]);
33+
Assert.AreEqual("hests", morph[7]);
34+
35+
}
36+
37+
[TestMethod]
38+
public void Webredaktør_Stem() {
39+
40+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
41+
42+
HunspellStemResult stem = analyzer.Stem("webredaktør").FirstOrDefault();
43+
44+
Assert.IsNotNull(stem);
45+
46+
string[] morph = analyzer.Morph(stem);
47+
48+
Assert.AreEqual(8, morph.Length);
49+
50+
Assert.AreEqual("webredaktør", morph[0]);
51+
Assert.AreEqual("webredaktørs", morph[1]);
52+
Assert.AreEqual("webredaktører", morph[2]);
53+
Assert.AreEqual("webredaktørerne", morph[3]);
54+
Assert.AreEqual("webredaktørernes", morph[4]);
55+
Assert.AreEqual("webredaktørers", morph[5]);
56+
Assert.AreEqual("webredaktøren", morph[6]);
57+
Assert.AreEqual("webredaktørens", morph[7]);
58+
59+
}
60+
61+
}
62+
63+
}
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Skybrud.TextAnalysis.Hunspell;
3+
using Skybrud.TextAnalysis.Hunspell.Stem;
4+
5+
namespace UnitTestProject1.Hunspell {
6+
7+
[TestClass]
8+
public class SpellTests {
9+
10+
[TestMethod]
11+
public void børnehave() {
12+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
13+
bool result = analyzer.Spell("børnehave");
14+
Assert.IsTrue(result);
15+
}
16+
17+
[TestMethod]
18+
public void børnehaver() {
19+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
20+
bool result = analyzer.Spell("børnehaver");
21+
Assert.IsTrue(result);
22+
}
23+
24+
[TestMethod]
25+
public void chefredaktør() {
26+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
27+
bool result = analyzer.Spell("chefredaktør");
28+
Assert.IsTrue(result);
29+
}
30+
31+
[TestMethod]
32+
public void webredaktør() {
33+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
34+
bool result = analyzer.Spell("webredaktør");
35+
Assert.IsTrue(result);
36+
}
37+
38+
[TestMethod]
39+
public void webredaktører() {
40+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
41+
bool result = analyzer.Spell("webredaktører");
42+
Assert.IsTrue(result);
43+
}
44+
45+
[TestMethod]
46+
public void somerhus() {
47+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
48+
bool result = analyzer.Spell("somerhus");
49+
Assert.IsFalse(result);
50+
}
51+
52+
[TestMethod]
53+
public void sommerhus() {
54+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
55+
bool result = analyzer.Spell("sommerhus");
56+
Assert.IsTrue(result);
57+
}
58+
59+
[TestMethod]
60+
public void avisuddeler() {
61+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
62+
bool result = analyzer.Spell("avisuddeler");
63+
Assert.IsTrue(result);
64+
}
65+
66+
[TestMethod]
67+
public void avisuddelerens() {
68+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
69+
bool result = analyzer.Spell("avisuddelerens");
70+
Assert.IsTrue(result);
71+
}
72+
73+
[TestMethod]
74+
public void Avisuddelerens2() {
75+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
76+
bool result = analyzer.Spell("Avisuddelerens");
77+
Assert.IsTrue(result);
78+
}
79+
80+
[TestMethod]
81+
public void karen() {
82+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
83+
bool result = analyzer.Spell("karen");
84+
Assert.IsFalse(result);
85+
}
86+
87+
[TestMethod]
88+
public void Karen() {
89+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
90+
bool result = analyzer.Spell("Karen");
91+
Assert.IsTrue(result);
92+
}
93+
94+
[TestMethod]
95+
public void landzonetilladelse() {
96+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
97+
bool result = analyzer.Spell("landzonetilladelse");
98+
Assert.IsTrue(result);
99+
}
100+
101+
[TestMethod]
102+
public void EAN() {
103+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
104+
bool result = analyzer.Spell("EAN");
105+
Assert.IsTrue(result);
106+
}
107+
108+
[TestMethod]
109+
public void ABCDEFG() {
110+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
111+
bool result = analyzer.Spell("ABCDEFG");
112+
Assert.IsFalse(result);
113+
}
114+
115+
}
116+
117+
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Skybrud.TextAnalysis.Hunspell;
3+
using Skybrud.TextAnalysis.Hunspell.Stem;
4+
5+
namespace UnitTestProject1.Hunspell {
6+
7+
[TestClass]
8+
public class StemTests {
9+
10+
[TestMethod]
11+
public void Hesten_Stem() {
12+
13+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
14+
15+
HunspellStemResult[] result = analyzer.Stem("hesten");
16+
17+
Assert.AreEqual(1, result.Length);
18+
19+
Assert.AreEqual("hest", result[0].Value);
20+
Assert.AreEqual("hest", result[0].Stem);
21+
Assert.AreEqual("", result[0].Prefix);
22+
23+
}
24+
25+
[TestMethod]
26+
public void Webredaktør_Stem() {
27+
28+
HunspellTextAnalyzer analyzer = UnitTestHelper.GetDanishTextAnalyzer();
29+
30+
HunspellStemResult[] result = analyzer.Stem("webredaktør");
31+
32+
Assert.AreEqual(1, result.Length);
33+
34+
Assert.AreEqual("webredaktør", result[0].Value);
35+
Assert.AreEqual("redaktør", result[0].Stem);
36+
Assert.AreEqual("web", result[0].Prefix);
37+
38+
}
39+
40+
}
41+
42+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.IO;
2+
using Skybrud.TextAnalysis.Hunspell;
3+
4+
namespace UnitTestProject1 {
5+
6+
public static class UnitTestHelper {
7+
8+
private static HunspellTextAnalyzer _danish;
9+
10+
public static HunspellTextAnalyzer GetDanishTextAnalyzer() {
11+
12+
if (_danish != null) return _danish;
13+
14+
string dll = typeof(UnitTestHelper).Assembly.Location;
15+
16+
string dir = Path.GetDirectoryName(dll);
17+
18+
string filename = "da_DK-2.6.229";
19+
20+
_danish = HunspellTextAnalyzer.CreateFromFiles($"{dir}/{filename}.dic", $"{dir}/{filename}.aff");
21+
22+
return _danish;
23+
24+
}
25+
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
12+
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
13+
<PackageReference Include="coverlet.collector" Version="1.3.0" />
14+
<PackageReference Include="Skybrud.Essentials" Version="1.1.34" />
15+
<PackageReference Include="WeCantSpell.Hunspell" Version="3.0.1" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\Skybrud.TextAnalysis\Skybrud.TextAnalysis.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<None Update="da_DK-2.6.229.aff">
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
</None>
26+
<None Update="da_DK-2.6.229.dic">
27+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
28+
</None>
29+
</ItemGroup>
30+
31+
</Project>

0 commit comments

Comments
 (0)