Beispiel #1
0
        public void ConvertToString()
        {
            //Tests for 0 through 99
            NumbersToWords test = new NumbersToWords();

            Assert.AreEqual("twenty", test.ConvertToWords(20));
            Assert.AreEqual("thirty seven", test.ConvertToWords(37));
            Assert.AreEqual("eighty four", test.ConvertToWords(84));
            Assert.AreEqual("thirty seven", test.ConvertToWords(37));
            Assert.AreEqual("five", test.ConvertToWords(5));
            Assert.AreEqual("zero", test.ConvertToWords(0));

            //Tests 100 through 999
            Assert.AreEqual("one hundred and twenty five", test.ConvertToWords(125));
            Assert.AreEqual("one hundred", test.ConvertToWords(100));
            Assert.AreEqual("nine hundred and ninety nine", test.ConvertToWords(999));

            //Tests 1000 through 9999));
            Assert.AreEqual("one thousand two hundred and twenty five", test.ConvertToWords(1225));
            Assert.AreEqual("nine thousand nine hundred and ninety five", test.ConvertToWords(9995));

            //Tests 10,000 through 99,999
            Assert.AreEqual("ten thousand", test.ConvertToWords(10000));
            Assert.AreEqual("twelve thousand", test.ConvertToWords(12000));
            Assert.AreEqual("fifteen thousand", test.ConvertToWords(15000));
            Assert.AreEqual("ninety nine thousand", test.ConvertToWords(99000));
            Assert.AreEqual("forty seven thousand one hundred and twenty five", test.ConvertToWords(47125));

            //***These numbers from the instructions are not grammatically correct***
            //eight hundred and three thousand and three hundred and eight
            //nine hundred and ninetynine thousand and nine-hundred and ninety-nine

            //Tests 100,000 through 999,999
            Assert.AreEqual("four hundred and fifty three thousand six hundred and seventy two", test.ConvertToWords(453672));
            Assert.AreEqual("nine hundred and sixty seven thousand four hundred and fifty eight", test.ConvertToWords(967458));
            Assert.AreEqual("five hundred thousand", test.ConvertToWords(500000));
            Assert.AreEqual("eight hundred and three thousand", test.ConvertToWords(803000));
            Assert.AreEqual("three hundred and eight", test.ConvertToWords(308));
            Assert.AreEqual("nine hundred and ninety nine thousand nine hundred and ninety nine", test.ConvertToWords(999999));
        }
Beispiel #2
0
        public void NumbersToWordsTest()
        {
            NumbersToWords numberInputTest = new NumbersToWords();

            string[] numberWordArray = { "zero",   "one",    "two",      "three",    "four",    "five",    "six",       "seven",    "eight", "nine", "ten",
                                         "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };

            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(numberWordArray[i], numberInputTest.ConvertToWords(i));
            }

            Assert.AreEqual("twenty", numberInputTest.ConvertToWords(20));
            Assert.AreEqual("twenty-one", numberInputTest.ConvertToWords(21));
            Assert.AreEqual("thirty", numberInputTest.ConvertToWords(30));
            Assert.AreEqual("forty", numberInputTest.ConvertToWords(40));
            Assert.AreEqual("fifty", numberInputTest.ConvertToWords(50));
            Assert.AreEqual("sixty", numberInputTest.ConvertToWords(60));
            Assert.AreEqual("seventy", numberInputTest.ConvertToWords(70));
            Assert.AreEqual("eighty", numberInputTest.ConvertToWords(80));
            Assert.AreEqual("ninety-nine", numberInputTest.ConvertToWords(99));

            Assert.AreEqual("three hundred", numberInputTest.ConvertToWords(300));
            Assert.AreEqual("three hundred and one", numberInputTest.ConvertToWords(301));
            Assert.AreEqual("four hundred and thirteen", numberInputTest.ConvertToWords(413));
            Assert.AreEqual("three hundred and twenty-one", numberInputTest.ConvertToWords(321));

            Assert.AreEqual("four thousand", numberInputTest.ConvertToWords(4000));
            Assert.AreEqual("four thousand and six", numberInputTest.ConvertToWords(4006));
            Assert.AreEqual("four thousand and sixteen", numberInputTest.ConvertToWords(4016));
            Assert.AreEqual("four thousand and twenty-six", numberInputTest.ConvertToWords(4026));
            Assert.AreEqual("four thousand and three hundred", numberInputTest.ConvertToWords(4300));
            Assert.AreEqual("four thousand and three hundred and six", numberInputTest.ConvertToWords(4306));
            Assert.AreEqual("four thousand and three hundred and sixteen", numberInputTest.ConvertToWords(4316));
            Assert.AreEqual("four thousand and two hundred and sixty-six", numberInputTest.ConvertToWords(4266));
            Assert.AreEqual("ten thousand", numberInputTest.ConvertToWords(10000));
            Assert.AreEqual("eighteen thousand and six", numberInputTest.ConvertToWords(18006));

            Assert.AreEqual("thirty-three thousand", numberInputTest.ConvertToWords(33000));
            Assert.AreEqual("thirty-three thousand and one", numberInputTest.ConvertToWords(33001));
            Assert.AreEqual("thirty-three thousand and eighteen", numberInputTest.ConvertToWords(33018));
            Assert.AreEqual("thirty-three thousand and twenty-eight", numberInputTest.ConvertToWords(33028));
            Assert.AreEqual("thirty-three thousand and one hundred", numberInputTest.ConvertToWords(33100));
            Assert.AreEqual("thirty-three thousand and one hundred and one", numberInputTest.ConvertToWords(33101));
            Assert.AreEqual("thirty-three thousand and one hundred and thirteen", numberInputTest.ConvertToWords(33113));
            Assert.AreEqual("thirty-three thousand and one hundred and forty-five", numberInputTest.ConvertToWords(33145));

            Assert.AreEqual("one hundred thousand", numberInputTest.ConvertToWords(100000));
            Assert.AreEqual("one hundred and one thousand", numberInputTest.ConvertToWords(101000));
            Assert.AreEqual("one hundred and eleven thousand", numberInputTest.ConvertToWords(111000));
            Assert.AreEqual("three hundred and thirteen thousand", numberInputTest.ConvertToWords(313000));
            Assert.AreEqual("three hundred and twenty-three thousand", numberInputTest.ConvertToWords(323000));

            Assert.AreEqual("one hundred thousand and one", numberInputTest.ConvertToWords(100001));
            Assert.AreEqual("one hundred thousand and eighteen", numberInputTest.ConvertToWords(100018));
            Assert.AreEqual("one hundred thousand and twenty-one", numberInputTest.ConvertToWords(100021));

            Assert.AreEqual("three hundred and twenty-three thousand and one hundred", numberInputTest.ConvertToWords(323100));
            Assert.AreEqual("three hundred and twenty-three thousand and one hundred and one", numberInputTest.ConvertToWords(323101));
            Assert.AreEqual("three hundred and twenty-three thousand and one hundred and eighteen", numberInputTest.ConvertToWords(323118));
            Assert.AreEqual("three hundred and twenty-three thousand and six hundred and forty-five", numberInputTest.ConvertToWords(323645));
        }