-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cs
217 lines (202 loc) · 10.2 KB
/
Test.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using NUnit.Framework;
namespace Algorithms
{
[TestFixture]
internal class Test
{
private IAlgorithms Algorithms = new Algorithms();
[Test]
public void TestChunkArrayInGroups()
{
// 1
object[] param1 = new object[] { 0, 1, 2, 3, 4, 5 };
object[][] test1 = new object[][]{
new object[] {0,1,2},
new object[] {3,4,5},
};
Assert.AreEqual(test1, Algorithms.ChunkArrayInGroups(param1, 3));
// 2
object[] param2 = new object[] { 0, 1, 2, 3, 4, 5 };
object[][] test2 = new object[][]{
new object[] {0,1},
new object[] {2,3},
new object[] {4,5}
};
Assert.AreEqual(test2, Algorithms.ChunkArrayInGroups(param2, 2));
// 3
object[] param3 = new object[] { 0, 1, 2, 3, 4, 5 };
object[][] test3 = new object[][]{
new object[] {0,1,2,3},
new object[] {4,5}
};
Assert.AreEqual(test3, Algorithms.ChunkArrayInGroups(param3, 4));
// 4
object[] param4 = new object[] { 0, 1, 2, 3, 4, 5, 6 };
object[][] test4 = new object[][]{
new object[] {0,1,2},
new object[] {3,4,5},
new object[] {6}
};
Assert.AreEqual(test4, Algorithms.ChunkArrayInGroups(param4, 3));
// 5
object[] param5 = new object[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
object[][] test5 = new object[][]{
new object[] {0,1,2,3},
new object[] {4,5,6,7},
new object[] {8}
};
Assert.AreEqual(test5, Algorithms.ChunkArrayInGroups(param5, 4));
// 6
object[] param6 = new object[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
object[][] test6 = new object[][]{
new object[] {0,1},
new object[] {2,3},
new object[] {4,5},
new object[] {6,7},
new object[] {8}
};
Assert.AreEqual(test6, Algorithms.ChunkArrayInGroups(param6, 2));
}
[Test]
public void TestConfirmEnding()
{
Assert.AreEqual(true, Algorithms.ConfirmEnding("Bastian", "n"));
Assert.AreEqual(true, Algorithms.ConfirmEnding("Open sesame", "same"));
Assert.AreEqual(true, Algorithms.ConfirmEnding("He has to give me a new name", "name"));
Assert.AreEqual(false, Algorithms.ConfirmEnding("Connor", "n"));
Assert.AreEqual(false, Algorithms.ConfirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain"));
Assert.AreEqual(false, Algorithms.ConfirmEnding("Open sesame", "pen"));
Assert.AreEqual(false, Algorithms.ConfirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification"));
}
[Test]
public void TestDestroyer()
{
Assert.AreEqual(new object[] { 1, 1 }, Algorithms.Destroyer(new object[] { 1, 2, 3, 1, 2, 3 }, 2, 3));
Assert.AreEqual(new object[] { 1, 5, 1 }, Algorithms.Destroyer(new object[] { 1, 2, 3, 5, 1, 2, 3 }, 2, 3));
Assert.AreEqual(new object[] { 1 }, Algorithms.Destroyer(new object[] { 3, 5, 1, 2, 2 }, 2, 3, 5));
Assert.AreEqual(new object[] { }, Algorithms.Destroyer(new object[] { 2, 3, 2, 3 }, 2, 3));
Assert.AreEqual(new object[] { "hamburger" }, Algorithms.Destroyer(new object[] { "tree", "hamburger", 53 }, "tree", 53));
}
[Test]
public void TestFactorialize()
{
Assert.AreEqual(120, Algorithms.Factorialize(5));
Assert.AreEqual(3628800, Algorithms.Factorialize(10));
Assert.AreEqual("2432902008176640000", Algorithms.Factorialize(20).ToString());
Assert.AreEqual(1, Algorithms.Factorialize(0));
}
[Test]
public void TestFindLongestWord()
{
Assert.AreEqual(6, Algorithms.FindLongestWord("The quick brown fox jumped over the lazy dog"));
Assert.AreEqual(5, Algorithms.FindLongestWord("May the force be with you"));
Assert.AreEqual(6, Algorithms.FindLongestWord("Google do a barrel roll"));
Assert.AreEqual(8, Algorithms.FindLongestWord("What is the average airspeed velocity of an unladen swallow"));
Assert.AreEqual(19, Algorithms.FindLongestWord("What if we try a super-long word such as otorhinolaryngology"));
}
[Test]
public void TestGetIndexToIns()
{
Assert.AreEqual(3, Algorithms.GetIndexToIns(new object[] { 10, 20, 30, 40, 50 }, 35));
Assert.AreEqual(2, Algorithms.GetIndexToIns(new object[] { 10, 20, 30, 40, 50 }, 30));
Assert.AreEqual(1, Algorithms.GetIndexToIns(new object[] { 40, 60 }, 50));
Assert.AreEqual(0, Algorithms.GetIndexToIns(new object[] { 3, 10, 5 }, 3));
Assert.AreEqual(2, Algorithms.GetIndexToIns(new object[] { 5, 3, 20, 3 }, 5));
Assert.AreEqual(2, Algorithms.GetIndexToIns(new object[] { 2, 20, 10 }, 19));
Assert.AreEqual(3, Algorithms.GetIndexToIns(new object[] { 2, 5, 10 }, 15));
}
[Test]
public void TestlargestOfFour()
{
int[][] arr = new int[][]{
new int[] {13,27,18,26},
new int[] {4,5,1,3},
new int[] {32,35,37,39},
new int[] {1000,1001,857,1}
};
Assert.AreEqual(new int[] { 27, 5, 39, 1001 }, Algorithms.LargestOfFour(arr));
}
[Test]
public void TestPalindrome()
{
Assert.True(Algorithms.Palindrome("eye"));
Assert.True(Algorithms.Palindrome("_eye"));
Assert.True(Algorithms.Palindrome("race car"));
Assert.False(Algorithms.Palindrome("not a palindrome"));
Assert.True(Algorithms.Palindrome("A man, a plan, a canal. Panama"));
Assert.True(Algorithms.Palindrome("never odd or even"));
Assert.False(Algorithms.Palindrome("nope"));
Assert.False(Algorithms.Palindrome("almostomla"));
Assert.True(Algorithms.Palindrome("My age is 0, 0 si ega ym."));
Assert.False(Algorithms.Palindrome("1 eye for of 1 eye."));
Assert.True(Algorithms.Palindrome("0_0 (: /-\\ :) 0-0"));
Assert.False(Algorithms.Palindrome("five|\\_/|four"));
}
[Test]
public void TestRepeatStringNumTimes()
{
Assert.AreEqual("***", Algorithms.RepeatStringNumTimes("*", 3));
Assert.AreEqual("********", Algorithms.RepeatStringNumTimes("*", 8));
Assert.AreEqual("abcabcabc", Algorithms.RepeatStringNumTimes("abc", 3));
Assert.AreEqual("abcabcabcabc", Algorithms.RepeatStringNumTimes("abc", 4));
Assert.AreEqual("abc", Algorithms.RepeatStringNumTimes("abc", 1));
Assert.AreEqual("", Algorithms.RepeatStringNumTimes("abc", -2));
}
[Test]
public void TestRevesreString()
{
Assert.AreEqual("olleh", Algorithms.ReverseString("hello"));
Assert.AreEqual("ydwoH", Algorithms.ReverseString("Howdy"));
Assert.AreEqual("htraE morf sgniteerG", Algorithms.ReverseString("Greetings from Earth"));
}
[Test]
public void TestRot13()
{
Assert.AreEqual("FREE CODE CAMP", Algorithms.Rot13("SERR PBQR PNZC"));
Assert.AreEqual("FREE PIZZA!", Algorithms.Rot13("SERR CVMMN!"));
Assert.AreEqual("FREE LOVE?", Algorithms.Rot13("SERR YBIR?"));
Assert.AreEqual("THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.", Algorithms.Rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK."));
}
[Test]
public void TestSlasher()
{
Assert.AreEqual(new object[] { 3 }, Algorithms.Slasher(new object[] { 1, 2, 3 }, 3));
Assert.AreEqual(new object[] { 1, 2, 3 }, Algorithms.Slasher(new object[] { 1, 2, 3 }, 0));
Assert.AreEqual(new object[] { }, Algorithms.Slasher(new object[] { 1, 2, 3 }, 9));
Assert.AreEqual(new object[] { }, Algorithms.Slasher(new object[] { 1, 2, 3 }, 4));
}
[Test]
public void TestTitleCase()
{
Assert.AreEqual("I'm A Little Tea Pot", Algorithms.TitleCase("I'm a little tea pot"));
Assert.AreEqual("Short And Stout", Algorithms.TitleCase("sHoRt AnD sToUt"));
Assert.AreEqual("Here Is My Handle Here Is My Spout", Algorithms.TitleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
}
[Test]
public void TestTruncateString()
{
string[] arrParam = new string[] {
"A-tisket a-tasket A green and yellow basket",
"Peter Piper picked a peck of pickled peppers",
"A-tisket a-tasket A green and yellow basket",
"A-tisket a-tasket A green and yellow basket",
"A-",
"Absolutely Longer"
};
string[] arrExp = new string[] {
"A-tisket...",
"Peter Piper...",
"A-tisket a-tasket A green and yellow basket",
"A-tisket a-tasket A green and yellow basket",
"A...",
"Ab..."
};
Assert.AreEqual(arrExp[0], Algorithms.TruncateString(arrParam[0], 11));
Assert.AreEqual(arrExp[1], Algorithms.TruncateString(arrParam[1], 14));
Assert.AreEqual(arrExp[2], Algorithms.TruncateString(arrParam[2], arrParam[2].Length));
Assert.AreEqual(arrExp[3], Algorithms.TruncateString(arrParam[3], arrParam[3].Length + 2));
Assert.AreEqual(arrExp[4], Algorithms.TruncateString(arrParam[4], 1));
Assert.AreEqual(arrExp[5], Algorithms.TruncateString(arrParam[5], 2));
}
}
}