-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextGenerator_Tests.cs
177 lines (162 loc) · 5.93 KB
/
TextGenerator_Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace TextAnalysis
{
[TestFixture]
public class TextGenerator_Tests
{
[TestCase("x", 10)]
[TestCase("a b c", 1)]
[Order(00)]
public void ContinuePhrase_DoNothing_OnEmptyDictionary(string phraseStart, int phraseWordsCount)
{
var actual = TextGenerator.ContinuePhrase(
new Dictionary<string, string>(),
phraseStart,
phraseWordsCount);
Assert.AreEqual(phraseStart, actual);
}
[Test]
[Order(05)]
public void ContinuePhrase_DoNothing_WhenWordsCountIsZero()
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"x", "y"}
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, "x", 0);
Assert.AreEqual("x", actual);
}
[TestCase("x", "y z")]
[TestCase("y", "z x")]
[TestCase("y", "z x")]
[TestCase("a", "b")]
[TestCase("z", "x y")]
[TestCase("a x", "y z")]
[TestCase("a b x", "y z")]
[TestCase("y z x", "y z")]
[TestCase("w x", "y z")]
[Order(10)]
public void ContinuePhrase_WhenNoTrigrams(string phraseBeginning, string expectedNextWord)
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"x", "y"},
{"y", "z"},
{"z", "x"},
{"a", "b" }
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, phraseBeginning, 2);
Assert.AreEqual(phraseBeginning + " " + expectedNextWord, actual);
}
[TestCase("x", 1, "x y")]
[TestCase("x", 2, "x y z")]
[TestCase("x", 3, "x y z")]
[TestCase("x", 100, "x y z")]
[TestCase("x y", 100, "x y z")]
[TestCase("x x", 2, "x x y z")]
[TestCase("y x", 1, "y x y")]
[TestCase("y y", 1, "y y q")]
[TestCase("y z", 1, "y z")]
[TestCase("a b x y", 1, "a b x y z")]
[TestCase("a b y", 1, "a b y q")]
[TestCase("y", 100, "y q")]
[Order(10)]
public void ContinuePhrase(string phraseBeginning, int wordsCount, string expectedResult)
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"x", "y"},
{"x y", "z"},
{"y", "q"}
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, phraseBeginning, wordsCount);
Assert.AreEqual(expectedResult, actual);
}
[TestCase("x y", "z")]
[TestCase("x y z", "w")]
[TestCase("y z", "w")]
[TestCase("x y z w", "v")]
[TestCase("y z w", "v")]
[TestCase("z w", "v")]
[Order(15)]
public void ContinuePhraseWithTrigrams(string phraseBeginning, string expectedNextWord)
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"x", "y"},
{"x y", "z"},
{"y z", "w"},
{"z w", "v"},
{"y", "a"},
{"z", "b"}
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, phraseBeginning, 1);
Assert.AreEqual(phraseBeginning + " " + expectedNextWord, actual);
}
[Test]
[Order(10)]
public void ContinuePhrase_StopWhenNoBigrammsAndTrigramms()
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"x", "y"},
{"x y", "z"},
{"y", "q"}
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, "x", 4);
Assert.AreEqual("x y z", actual);
}
[TestCase("x", "")]
[TestCase("hello", "everybody")]
[TestCase("hello everybody", "be")]
[TestCase("hello everybody be", "cool")]
[TestCase("everybody be", "cool")]
[TestCase("be", "")]
[TestCase("goodbye", "")]
[TestCase("be cool", "")]
[Order(20)]
public void ContinuePhrase_WithMultiletterWords(string phraseBeginning, string expectedNextWord)
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"hello", "everybody"},
{"everybody be", "cool"},
{"everybody", "be"}
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, phraseBeginning, 1);
var expected = string.IsNullOrEmpty(expectedNextWord) ? phraseBeginning : phraseBeginning + " " + expectedNextWord;
Assert.AreEqual(expected, actual);
}
[Order(50)]
[TestCase("x", 2, "x x x")]
[TestCase("x", 5, "x x x x x x")]
[TestCase("y", 3, "y x x x")]
[TestCase("z", 3, "z y x x")]
[TestCase("a", 3, "a b c a")]
[TestCase("a", 7, "a b c a b c a b")]
[TestCase("b b", 7, "b b c a b c a b c")]
public void ContinuePhrase_WhenCycleInDictionary(string phraseBeginning, int wordsCount, string expectedResult)
{
var mostFrequentNextWords = new Dictionary<string, string>
{
{"x", "x"},
{"a", "b"},
{"b", "c"},
{"c", "a"},
{"y", "x"},
{"z", "y"},
};
var actual =
TextGenerator.ContinuePhrase(mostFrequentNextWords, phraseBeginning, wordsCount);
Assert.AreEqual(expectedResult, actual);
}
}
}