コード例 #1
0
        /// <summary>
        /// Task 4.1
        /// This method repeatedly displays a small menu to the user so that they
        /// can test that the DistanceConverter can convert
        /// an entered number of miles into feet, or the number of feet
        /// into miles.
        /// </summary>
        private static void TestDistanceConverter()
        {
            T41_DistanceConverter converter = new T41_DistanceConverter();

            string[] choices =
            {
                "1. Convert Miles to Feet",
                "2. Convert Feet to Miles",
                "3. Quit Program"
            };

            int choice = 0;

            do
            {
                SimpleIO.WriteTitle("Distance Converter", "Task 4.1");

                choice = SimpleIO.GetChoice(choices);

                if (choice == 1)
                {
                    double miles = converter.GetNumber("Miles");
                    double feet  = converter.ToFeet(miles);

                    Console.WriteLine("No of Feet = " + feet);
                }
                else if (choice == 2)
                {
                    double feet  = converter.GetNumber("Feet");
                    double miles = converter.ToMiles(feet);

                    Console.WriteLine("No of Miles = " + miles);
                }
            } while (choice != 3);
        }
コード例 #2
0
        public void TestDistanceConverter()
        {
            double miles = 1;
            double feet  = converter.ToFeet(miles);

            Assert.AreEqual(feet, T41_DistanceConverter.FEET_IN_MILES);
        }