Exemplo n.º 1
0
        public void Convert_Is_Able_To_Convert_Twenty_To_TwentyNine()
        {
            // Arrange
            Dictionary <int, string> entries = new Dictionary <int, string>()
            {
                { 20, "zwanzig" },
                { 21, "ein und zwanzig" },
                { 22, "zwei und zwanzig" },
                { 23, "drei und zwanzig" },
                { 24, "vier und zwanzig" },
                { 25, "fünf und zwanzig" },
                { 26, "sechs und zwanzig" },
                { 27, "sieben und zwanzig" },
                { 28, "acht und zwanzig" },
                { 29, "neun und zwanzig" },
            };

            NumberConverter target = new NumberConverter();

            foreach (var entry in entries)
            {
                // Act
                var result = target.Convert(entry.Key);

                // Assert
                Assert.AreEqual(entry.Value, result);
            }
        }
Exemplo n.º 2
0
        public Transition Parse(string xml)
        {
            var r   = new Transition();
            var doc = new XmlDocument();

            doc.LoadXml(xml);

            var e = doc.GetElementsByTagName("transition")[0];

            r.Type = e.Attributes["type"].Value;
            r.Time = NumberConverter.Convert(e.Attributes["time"].Value);
            if (e.Attributes["flashes"] != null)
            {
                r.FlashTimes = NumberConverter.Convert(e.Attributes["flashes"].Value);
            }

            foreach (XmlNode child in e.ChildNodes)
            {
                if (child.Name == "property")
                {
                    var p = new Property
                    {
                        Name  = child.Attributes["name"].Value,
                        Type  = child.Attributes["type"].Value,
                        Value = child.Attributes["value"].Value
                    };
                    r.Properties.Add(p);
                }
            }

            return(r);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            NumberConverter converter = new NumberConverter();

            System.Console.WriteLine("Type \"exit\" to close the application...");

            while (true)
            {
                System.Console.WriteLine("\nEnter a number:");

                string input = System.Console.ReadLine();

                if (input == "exit")
                {
                    break;
                }
                else
                {
                    int value = 0;

                    if (!int.TryParse(input, out value))
                    {
                        System.Console.WriteLine("Error");
                    }
                    else
                    {
                        System.Console.WriteLine(converter.Convert(value));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Convert_Produces_Proper_Output_For_Twenty_To_Ninety()
        {
            // Arrange
            Dictionary <int, string> entries = new Dictionary <int, string>()
            {
                { 20, "zwanzig" },
                { 30, "dreißig" },
                { 40, "vierzig" },
                { 50, "fünfzig" },
                { 60, "sechzig" },
                { 70, "siebzig" },
                { 80, "achtzig" },
                { 90, "neunzig" },
            };

            NumberConverter target = new NumberConverter();

            foreach (var entry in entries)
            {
                // Act
                var result = target.Convert(entry.Key);

                // Assert
                Assert.AreEqual(entry.Value, result);
            }
        }
Exemplo n.º 5
0
    private void PrintTables(int start, int end, params NumberSystem[] numberSystems)
    {
        string[,] cells = new string[end - start + 1, 1 + numberSystems.Length];
        for (int i = 0; i <= end - start; i++)
        {
            cells[i, 0] = (start + i - 1).ToString();
            for (int j = 0; j < numberSystems.Length; j++)
            {
                var numberSystem = numberSystems[j];
                if (i == 0)
                {
                    cells[i, j + 1] = numberSystem.ToString();
                }
                else
                {
                    var decimalNumber     = (start + i - 1).ToString();
                    var numberInSystem    = NumberConverter.Convert(decimalNumber, NumberSystem.Decimal, numberSystem);
                    var decimalNumberBack = numberInSystem.ToDecimal();
                    cells[i, j + 1] = decimalNumberBack.Value;
                }
            }
        }
        var output = cells.ToStringTable();

        Console.WriteLine(output);
    }
Exemplo n.º 6
0
        /// <summary>
        /// Extends System.UInt64 and returns the textual representation of its value
        /// </summary>
        /// <param name="number">The number to be converted to text</param>
        /// <returns>A steing holds the textual representation of the given number</returns>
        public static string ToText(this ulong number)
        {
            NumberConverter converter = new NumberConverter();

            string convertedNumber = converter.Convert(number);

            return(convertedNumber);
        }
Exemplo n.º 7
0
 public void ParseToDecimal()
 {
     for (int i = 0; i < 2500; i++)
     {
         var numberAsString = i.ToString();
         var parsedNumber   = NumberConverter.Convert(numberAsString, NumberSystem.Decimal, NumberSystem.Decimal);
         numberAsString.Should().Be(parsedNumber.Value);
     }
 }
Exemplo n.º 8
0
        public void Ensure_Proper_Endings()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var resultMillionSingular = target.Convert(1000000);
            var resultMillionPlural   = target.Convert(2000000);

            var resultBillionSingular = target.Convert(1000000000);
            var resultBillionPlural   = target.Convert(2000000000);

            // Assert
            Assert.IsTrue(resultMillionSingular.EndsWith("million"));
            Assert.IsTrue(resultMillionPlural.EndsWith("millionen"));

            Assert.IsTrue(resultBillionSingular.EndsWith("milliarde"));
            Assert.IsTrue(resultBillionPlural.EndsWith("milliarden"));
        }
Exemplo n.º 9
0
        public void ConvertTest(ulong number, string expected)
        {
            var bc = new NumberConverter();

            var actual = bc.Convert(number);

            TestContext.Out.WriteLine($"{number} : {actual}");

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
    public static int ToDecimalValue(this Number number)
    {
        var decimalNumber = number.NumberSystem == NumberSystem.Decimal
            ? number
            : NumberConverter.Convert(number, NumberSystem.Decimal);
        var stringRepresentation = decimalNumber.Value;
        var intValue             = int.Parse(stringRepresentation);

        return(intValue);
    }
        public void Entering_the_number_649_results_in_roman_numeral_DCXLIX()
        {
            // Arrange
            var number          = 649;
            var numberConverter = new NumberConverter();
            // Act
            var result = numberConverter.Convert(number);

            // Assert
            Assert.AreEqual("DCXLIX", result);
        }
        private string[] GetWords(int[] firstNumbers)
        {
            var numbers = new List <string>();

            foreach (var number in firstNumbers)
            {
                numbers.Add(NumberConverter.Convert(number));
            }

            return(numbers.ToArray());
        }
        public void Entering_the_number_1_results_in_roman_numeral_I()
        {
            // Arrange
            var number          = 1;
            var numberConverter = new NumberConverter();
            // Act
            var result = numberConverter.Convert(number);

            // Assert
            Assert.AreEqual("I", result);
        }
Exemplo n.º 14
0
        public void Convert_Produces_Proper_Output_For_One_Thousand()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(1000);

            // Assert
            Assert.AreEqual("ein tausend", result);
        }
        public void Entering_the_number_2014_results_in_roman_numeral_MMXIV()
        {
            // Arrange
            var number          = 2014;
            var numberConverter = new NumberConverter();
            // Act
            var result = numberConverter.Convert(number);

            // Assert
            Assert.AreEqual("MMXIV", result);
        }
        public void Entering_the_number_798_results_in_roman_numeral_DCCXCVIII()
        {
            // Arrange
            var number          = 798;
            var numberConverter = new NumberConverter();
            // Act
            var result = numberConverter.Convert(number);

            // Assert
            Assert.AreEqual("DCCXCVIII", result);
        }
Exemplo n.º 17
0
        public void Convert_Produces_Proper_Output_For_999()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(999);

            // Assert
            Assert.AreEqual("neun hundert neun und neunzig", result);
        }
Exemplo n.º 18
0
        public void Convert_Produces_Proper_Output_For_1234()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(1234);

            // Assert
            Assert.AreEqual("ein tausend zwei hundert vier und dreißig", result);
        }
Exemplo n.º 19
0
        public void Convert_Produces_Proper_Output_For_1234567890()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(1234567890);

            // Assert
            Assert.AreEqual("eine milliarde zwei hundert vier und dreißig millionen fünf hundert sieben und sechzig tausend acht hundert neunzig", result);
        }
Exemplo n.º 20
0
        public void Convert_One_Returns_String_Eins()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(1);

            // Assert
            Assert.AreEqual("eins", result);
        }
Exemplo n.º 21
0
        public void Convert_Zero_Returns_String_Null()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(0);

            // Assert
            Assert.AreEqual("null", result);
        }
        public void Entering_the_number_3999_results_in_roman_numeral_MMMCMXCIX()
        {
            // Arrange
            var number          = 3999;
            var numberConverter = new NumberConverter();
            // Act
            var result = numberConverter.Convert(number);

            // Assert
            Assert.AreEqual("MMMCMXCIX", result);
        }
Exemplo n.º 23
0
        public void Convert_Produces_Proper_Output_For_116()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(116);

            // Assert
            Assert.AreEqual("ein hundert sechzehn", result);
        }
Exemplo n.º 24
0
        public void Convert_Method_Returns_Not_An_Empty_Or_Null_String()
        {
            // Arrange
            NumberConverter target = new NumberConverter();

            // Act
            var result = target.Convert(0);

            // Assert
            Assert.IsFalse(String.IsNullOrEmpty(result));
        }
Exemplo n.º 25
0
 static void SaveToFiles(List <int> numbers)
 {
     foreach (var number in numbers)
     {
         string path = number.ToString() + ".txt";
         using (StreamWriter sw = new StreamWriter(path))
         {
             CheckExistence(path);
             sw.WriteLine(NumberConverter.Convert(number));
         }
     }
 }
Exemplo n.º 26
0
        public Effects.Transition ToTransition <T>(Transition t, T target)
        {
            ITransitionType tp;

            switch (t.Type)
            {
            case "linear":
                tp = new TransitionType_Linear(t.Time);
                break;

            case "bounce":
                tp = new TransitionType_Bounce(t.Time);
                break;

            case "flash":
                tp = new TransitionType_Flash(t.FlashTimes, t.Time);
                break;

            case "deceleration":
                tp = new TransitionType_Deceleration(t.Time);
                break;

            case "throwcatch":
                tp = new TransitionType_ThrowAndCatch(t.Time);
                break;

            default:
                tp = new TransitionType_Linear(t.Time);
                break;
            }
            var r = new Effects.Transition(tp);

            foreach (var property in t.Properties)
            {
                object val = null;

                switch (property.Type)
                {
                case "int":
                    val = NumberConverter.Convert(property.Value);
                    break;

                case "color":
                    val = ColorConverter.Convert(property.Value);
                    break;
                }

                r.add(target, property.Name, val);
            }

            return(r);
        }
Exemplo n.º 27
0
        private void convertInput()
        {
            int value = 0;

            if (!int.TryParse(txb_Input.Text, out value))
            {
                txb_Output.Text = "Error";
            }
            else
            {
                txb_Output.Text = _converter.Convert(value);
            }
        }
Exemplo n.º 28
0
        public PartialViewResult GetNumberInWords(int value)
        {
            string result = string.Empty;

            if (ViewData.ModelState.IsValid)
            {
                NumberConverter converter = new NumberConverter();
                result = converter.Convert(value);
            }
            else
            {
                result = "Error";
            }

            return(PartialView((object)result));
        }
        /// <summary>
        /// This method calculates the cost to level this hero by the number specified.
        /// </summary>
        /// <param name="n">Number of levels to calculate for</param>
        /// <returns>The cost to level the hero</returns>
        public string calculateLevelUpCost(int n)
        {
            double cost = 0.0;

            if (_hero.ID == 1)
            {
                for (int i = 0; i < n; i++)
                {
                    cost += Math.Floor(Math.Min(20, 5 + Level + i) * Math.Pow(1.07, Level + i));
                }
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    cost += Math.Floor(_hero.BaseCost * Math.Pow(1.07, Level + i));
                }
            }

            return(NumberConverter.Convert(cost));
        }
Exemplo n.º 30
0
        public void Convert_Is_Able_To_Convert_From_Zero_To_Nineteen()
        {
            // Arrange
            Dictionary <int, string> entries = new Dictionary <int, string>()
            {
                { 0, "null" },
                { 1, "eins" },
                { 2, "zwei" },
                { 3, "drei" },
                { 4, "vier" },
                { 5, "fünf" },
                { 6, "sechs" },
                { 7, "sieben" },
                { 8, "acht" },
                { 9, "neun" },
                { 10, "zehn" },
                { 11, "elf" },
                { 12, "zwölf" },
                { 13, "dreizehn" },
                { 14, "vierzehn" },
                { 15, "fünfzehn" },
                { 16, "sechzehn" },
                { 17, "siebzehn" },
                { 18, "achtzehn" },
                { 19, "neunzehn" },
            };

            NumberConverter target = new NumberConverter();

            foreach (var entry in entries)
            {
                // Act
                var result = target.Convert(entry.Key);

                // Assert
                Assert.AreEqual(entry.Value, result);
            }
        }