コード例 #1
0
ファイル: Program.cs プロジェクト: newdevin/Kata
        static void Main(string[] args)
        {

            NumberConverter nc = new NumberConverter();
            string result = nc.FromNumberToWords((long)1e18 + 30 );
            Console.WriteLine(result);

        }
コード例 #2
0
ファイル: NumberConverterTest.cs プロジェクト: newdevin/Kata
        public void FromNumberToWords_11to19()
        {
            string[] str = new string[] { "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen" };

            NumberConverter nc = new NumberConverter();
            int si = 11;
            int count = 9;
            foreach (var i in Enumerable.Range(si, count))
            {
                var result = nc.FromNumberToWords(i);
                Assert.AreEqual(str[i - si], result);
            }
        }
コード例 #3
0
ファイル: NumberConverterTest.cs プロジェクト: newdevin/Kata
        public void FromNumberToWords_0to10()
        {
            string[] str = new string[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };

            NumberConverter nc = new NumberConverter();
            foreach (var i in Enumerable.Range(0, 11))
            {
                var result = nc.FromNumberToWords(i);
                Assert.AreEqual(str[i], result);

            }

        }
コード例 #4
0
ファイル: NumberConverterTest.cs プロジェクト: newdevin/Kata
        public void FromNumberToWords_20To99()
        {
            string[] str = new string[] { "", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine" };

            NumberConverter nc = new NumberConverter();

            var range = Enumerable.Range(20, 8);
            foreach (var i in range)
            {
                string exp = "";
                string result = "";

                if (i >= 20 && i <= 29)
                    exp = "twenty" + str[i - 20];
                if (i >= 30 && i <= 39)
                    exp = "thirty" + str[i - 30];
                if (i >= 40 && i <= 49)
                    exp = "fourty" + str[i - 40];
                if (i >= 50 && i <= 59)
                    exp = "fifty" + str[i - 50];
                if (i >= 60 && i <= 69)
                    exp = "sixty" + str[i - 60];
                if (i >= 70 && i <= 79)
                    exp = "seventy" + str[i - 70];
                if (i >= 80 && i <= 89)
                    exp = "eighty" + str[i - 80];
                if (i >= 90 && i <= 99)
                    exp = "ninty" + str[i - 90];

                result = nc.FromNumberToWords(i);

                Assert.AreEqual(exp, result);

            }


        }
コード例 #5
0
ファイル: NumberConverterTest.cs プロジェクト: newdevin/Kata
        public void FromNumberToWords_Random100To999()
        {
            
            NumberConverter nc = new NumberConverter();
            string result = nc.FromNumberToWords(100);
            var exp = "one hundred,hundred".Split(new string[] { "," }, StringSplitOptions.None);
            Assert.IsTrue(exp.Any(d => d == result));

            result = nc.FromNumberToWords(101);
            Assert.AreEqual("one hundred one", result);


            result = nc.FromNumberToWords(110);
            Assert.AreEqual("one hundred ten", result);

            result = nc.FromNumberToWords(113);
            Assert.AreEqual("one hundred thirteen", result);

            result = nc.FromNumberToWords(199);
            Assert.AreEqual("one hundred ninty nine", result);

            result = nc.FromNumberToWords(250);
            Assert.AreEqual("two hundred fifty", result);

            result = nc.FromNumberToWords(999);
            Assert.AreEqual("nine hundred ninty nine", result);

            result = nc.FromNumberToWords(405);
            Assert.AreEqual("four hundred five", result);


        }
コード例 #6
0
ファイル: NumberConverterTest.cs プロジェクト: newdevin/Kata
        public void FromNumberToWords_Random1KTo1M()
        {
            NumberConverter nc = new NumberConverter();
            string result = nc.FromNumberToWords(10001);
            Assert.AreEqual("ten thousand one", result);


            result = nc.FromNumberToWords(123456);
            Assert.AreEqual("one hundred twenty three thousand four hundred fifty six", result);


            result = nc.FromNumberToWords(900000);
            Assert.AreEqual("nine hundred thousand", result);
        }