-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectTestClasses.cs
214 lines (193 loc) · 9.99 KB
/
projectTestClasses.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
using Xunit;
using System;
using System.Collections.Generic;
using Integer_To_English_Word;
public class testingClass
{
// Name: edgeBasicConditionTest
// Purpose: To test ten random use case values.
// Description: Takes the given random test values and converts them to the english language to test for correctness.
[Theory]
[InlineData("-262081978")]
[InlineData("1006935391")]
[InlineData("1670376543")]
[InlineData("1378669339")]
[InlineData("1047641375")]
[InlineData("675232136")]
[InlineData("527791378")]
[InlineData("-531405650")]
[InlineData("1571325509")]
[InlineData("225655")]
public void edgeBasicConditionTest(string value)
{
// Our list of possible correct answers.
List<string> correctEdgeAnswers = new List<string>(new string[] {
"negative two hundred sixty two million eighty one thousand nine hundred seventy eight ",
"one billion six million nine hundred thirty five thousand three hundred ninety one ",
"one billion six hundred seventy million three hundred seventy six thousand five hundred forty three ",
"one billion three hundred seventy eight million six hundred sixty nine thousand three hundred thirty nine ",
"one billion forty seven million six hundred forty one thousand three hundred seventy five ",
"six hundred seventy five million two hundred thirty two thousand one hundred thirty six ",
"five hundred twenty seven million seven hundred ninety one thousand three hundred seventy eight ",
"negative five hundred thirty one million four hundred five thousand six hundred fifty ",
"one billion five hundred seventy one million three hundred twenty five thousand five hundred nine ",
"two hundred twenty five thousand six hundred fifty five "
});
// Creates the test value and stores them in the corresponding variables.
int userNumber, sign, numberLength;
string reverseString;
formatNumber(new string[] {value}, out userNumber, out sign, out numberLength, out reverseString);
// Converts the test number to english.
StandardDictionaryNumbers numberLibrary = new StandardDictionaryNumbers(reverseString, sign, numberLength, userNumber);
// Takes the result and checks the list of correct answers for a match.
string result = numberLibrary.getEnglishNumber();
int index = correctEdgeAnswers.IndexOf(result);
if (index != -1)
{
Assert.Equal(correctEdgeAnswers[index], result);
}
else
{
Assert.True(false, "The number " + value + " was not properly converted to the english language. We got \"" + result + "\" instead.");
}
}
// Name: edgePositiveConditionTest
// Purpose: To test the positive edge case numbers and 0.
// Description: Takes the given positive edge cases and converts them to the english language to check for correctness.
[Theory]
[InlineData("0")]
[InlineData("1")]
[InlineData("9")]
[InlineData("10")]
[InlineData("99")]
[InlineData("100")]
[InlineData("999")]
[InlineData("1000")]
[InlineData("9999")]
[InlineData("10000")]
[InlineData("99999")]
[InlineData("100000")]
[InlineData("999999")]
[InlineData("1000000")]
[InlineData("9999999")]
[InlineData("10000000")]
[InlineData("99999999")]
[InlineData("100000000")]
[InlineData("999999999")]
[InlineData("1000000000")]
[InlineData("2147483646")]
[InlineData("2147483647")]
public void edgePositiveConditionTest(string value)
{
// Our list of possible correct answers.
List<string> correctEdgeAnswers = new List<string>(new string[] {
"zero ", "one ", "nine ", "ten ",
"ninety nine ", "one hundred ",
"nine hundred ninety nine ", "one thousand ",
"nine thousand nine hundred ninety nine ", "ten thousand ",
"ninety nine thousand nine hundred ninety nine ", "one hundred thousand ",
"nine hundred ninety nine thousand nine hundred ninety nine ", "one million ",
"nine million nine hundred ninety nine thousand nine hundred ninety nine ", "ten million ",
"ninety nine million nine hundred ninety nine thousand nine hundred ninety nine ", "one hundred million ",
"nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine ", "one billion ",
"two billion one hundred forty seven million four hundred eighty three thousand six hundred forty six ",
"two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven ",
});
// Creates the test value and stores them in the corresponding variables.
int userNumber, sign, numberLength;
string reverseString;
formatNumber(new string[] {value}, out userNumber, out sign, out numberLength, out reverseString);
// Converts the test number to english.
StandardDictionaryNumbers numberLibrary = new StandardDictionaryNumbers(reverseString, sign, numberLength, userNumber);
// Takes the result and checks the list of correct answers for a match.
string result = numberLibrary.getEnglishNumber();
int index = correctEdgeAnswers.IndexOf(result);
if (index != -1)
{
Assert.Equal(correctEdgeAnswers[index], result);
}
else
{
Assert.True(false, "The number " + value + " was not properly converted to the english language. We got \"" + result + "\" instead.");
}
}
// Name: edgeNegativeConditionTest
// Purpose: To test the negative edge case numbers and 0.
// Description: Takes the given negative edge cases and converts them to the english language to check for correctness.
[Theory]
[InlineData("-1")]
[InlineData("-9")]
[InlineData("-10")]
[InlineData("-99")]
[InlineData("-100")]
[InlineData("-999")]
[InlineData("-1000")]
[InlineData("-9999")]
[InlineData("-10000")]
[InlineData("-99999")]
[InlineData("-100000")]
[InlineData("-999999")]
[InlineData("-1000000")]
[InlineData("-9999999")]
[InlineData("-10000000")]
[InlineData("-99999999")]
[InlineData("-100000000")]
[InlineData("-999999999")]
[InlineData("-1000000000")]
[InlineData("-2147483647")]
[InlineData("-2147483648")]
public void edgeNegativeConditionTest(string value)
{
// Our list of possible correct answers.
List<string> correctEdgeAnswers = new List<string>(new string[] {
"negative one ", "negative nine ", "negative ten ",
"negative ninety nine ", "negative one hundred ",
"negative nine hundred ninety nine ", "negative one thousand ",
"negative nine thousand nine hundred ninety nine ", "negative ten thousand ",
"negative ninety nine thousand nine hundred ninety nine ", "negative one hundred thousand ",
"negative nine hundred ninety nine thousand nine hundred ninety nine ", "negative one million ",
"negative nine million nine hundred ninety nine thousand nine hundred ninety nine ", "negative ten million ",
"negative ninety nine million nine hundred ninety nine thousand nine hundred ninety nine ", "negative one hundred million ",
"negative nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine ", "negative one billion ",
"negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven ",
"negative two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight "
});
// Creates the test value and stores them in the corresponding variables.
int userNumber, sign, numberLength;
string reverseString;
formatNumber(new string[] {value}, out userNumber, out sign, out numberLength, out reverseString);
// Converts the test number to english.
StandardDictionaryNumbers numberLibrary = new StandardDictionaryNumbers(reverseString, sign, numberLength, userNumber);
// Takes the result and checks the list of correct answers for a match.
string result = numberLibrary.getEnglishNumber();
int index = correctEdgeAnswers.IndexOf(result);
if (index != -1)
{
Assert.Equal(correctEdgeAnswers[index], result);
}
else
{
Assert.True(false, "The number " + value + " was not properly converted to the english language. We got \"" + result + "\" instead.");
}
}
// Name: formatNumber
// Purpose: To make the given number's length be a multiple of 3 and reverse it.
// Description: Finds the number's real length based on whether it is positive or negative and uses
// that information to adjust the length accordingly and reverse it.
private static void formatNumber(string[] values, out int userNumber, out int sign, out int numberLength, out string reverseString)
{
// If the number is not a signed 32 bit integer, or if
// the user has provided too many arguments, inform them
// and exit the program.
userNumber = Program.IsValidInput(values);
// Determine whether the user's number is a negative or positive number
// and adjust length accordingly.
sign = Math.Sign(userNumber);
numberLength = sign >= 0 ? userNumber.ToString().Length : userNumber.ToString().Length - 1;
// Reverses the user's number and make its length a multiple of 3 in
// order to convert the number to english.
NumberFormatter formatter = new NumberFormatter();
reverseString = formatter.reverseNumber(userNumber);
formatter.formatNumberLength(ref reverseString, sign, ref numberLength);
}
}