public void charTo1DigitTest() { for (int i = 1; i < 10; i++) { string actual = _conversionToString.charToString1Digit(i); Assert.AreEqual(_list[i - 1], actual); } }
public string classification(string str) { int length = str.Length; char[] lastTwoDigits = new char[2]; if (length > 2) { lastTwoDigits[0] = str[length - 2]; lastTwoDigits[1] = str[length - 1]; } string result = null; switch (str.Length) { case 1: result = cts.charToString1Digit(str[0]); break; case 2: result = cts.charToString2Digit(str); break; case 3: result = cts.charToString1Digit(str[0]) + " Hundred"; if (new string(lastTwoDigits) != "00") { result = result + " And " + cts.charToString2Digit(new string(lastTwoDigits)); } break; case 4: result = cts.charToString1Digit(str[0]) + result + " Thousand "; if (str[1] != '0') { result = result + cts.charToString1Digit(str[1]) + " Hundred And "; } result = result + cts.charToString2Digit(new string(lastTwoDigits)); break; case 5: result = cts.charToString2Digit(new string(new char[] { str[0], str[1] })) + " Thousand "; if (str[2] != '0') { result = result + cts.charToString1Digit(str[2]) + " Hundred And "; } result = result + cts.charToString2Digit(new string(lastTwoDigits)); break; case 6: result = cts.charToString1Digit(str[0]) + " Hundred"; if (str[1] != '0' || str[2] != '0') { result = result + " And " + cts.charToString2Digit(new string(new char[] { str[1], str[2] })); } result = result + " Thousand "; if (str[3] != '0') { result = result + cts.charToString1Digit(str[3]) + " Hundred"; } if (new string(lastTwoDigits) != "00") { result = result + " And " + cts.charToString2Digit(new string(lastTwoDigits)); } break; case 7: result = cts.charToString1Digit(str[0]) + " Million"; if (str[1] != '0') { result = result + " " + cts.charToString1Digit(str[1]) + " Hundred"; } if (str[2] != '0' || str[3] != '0') { result = result + " And " + cts.charToString2Digit(new string(new char[] { str[2], str[3] })); } if (str[1] != '0' || str[2] != '0' || str[3] != '0') { result = result + " Thousand "; } if (str[4] != '0') { result = result + cts.charToString1Digit(str[4]) + " Hundred"; } if (new string(lastTwoDigits) != "00") { result = result + " And " + cts.charToString2Digit(new string(lastTwoDigits)); } break; case 8: result = cts.charToString2Digit(new string(new char[] { str[0], str[1] })) + " Million"; if (str[2] != '0') { result = result + " " + cts.charToString1Digit(str[2]) + " Hundred"; } if (str[3] != '0' || str[4] != '0') { result = result + " And " + cts.charToString2Digit(new string(new char[] { str[3], str[4] })); } if (str[2] != '0' || str[3] != '0' || str[4] != '0') { result = result + " Thousand "; } if (str[5] != '0') { result = result + cts.charToString1Digit(str[5]) + " Hundred"; } if (new string(lastTwoDigits) != "00") { result = result + " And " + cts.charToString2Digit(new string(lastTwoDigits)); } break; case 9: result = cts.charToString1Digit(str[0]) + " Hundred"; if (str[1] != '0' || str[2] != '0') { result = result + " And " + cts.charToString2Digit(new string(new char[] { str[1], str[2] })); } result = result + " Million"; if (str[3] != '0') { result = result + " " + cts.charToString1Digit(str[3]) + " Hundred"; } if (str[4] != '0' || str[5] != '0') { result = result + " And " + cts.charToString2Digit(new string(new char[] { str[4], str[5] })); } if (str[3] != '0' || str[4] != '0' || str[5] != '0') { result = result + " Thousand "; } if (str[6] != '0') { result = result + cts.charToString1Digit(str[6]) + " Hundred"; } if (new string(lastTwoDigits) != "00") { result = result + " And " + cts.charToString2Digit(new string(lastTwoDigits)); } break; default: throw new NotImplementedException(); } return(result); }