예제 #1
0
        private void BtnMileKm_Click(object sender, EventArgs e)
        {
            int    Mile;
            double Km = 1.61;

            while (true)
            {
                Mile = int.Parse(Microsoft.VisualBasic.Interaction.InputBox("Introduce your mileage", "Mile to km conversor", ""));

                if (Mile < 0)
                {
                    TxtAnswers.Text = "Please enter a positive number";
                }
                else
                {
                    double FinalKm = Mile * Km;
                    MessageBox.Show(Mile.ToString() + " miles are " + FinalKm.ToString("n2") + " Kms");
                }
                string response = Microsoft.VisualBasic.Interaction.InputBox("Do you want to keep converting miles to kms, y/n", "", "");
                if (response == "n" || response == "no" || response == "cancelar")
                {
                    break;
                }
            }
        }
예제 #2
0
        public void Should_format_string(string format, string mask)
        {
            var expected = string.Format(Consts.CultureEnUS, mask, 1.757899e2);

            var instance = new Mile(1.757899e2);
            var actual   = instance.ToString(format, Consts.CultureEnUS);

            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public void Should_convert_to_string(double value)
        {
            var expected = $"{value:e} mi";

            var instance = new Mile(value);
            var actual   = instance.ToString();

            Assert.AreEqual(expected, actual);
        }
예제 #4
0
            public void MultiplyDivide()
            {
                MPH    speed    = (MPH)100.0;   // 100 mph
                Minute duration = (Minute)30.0; // 30 minutes

                Mile miles = speed * (Hour)duration;

                Assert.AreEqual((Mile)50.0, miles);
                Assert.AreEqual("50 mil", miles.ToString(CultureInfo.InvariantCulture));

                Kilometer kilometers = (Kilometer)miles;

                Assert.AreEqual((Kilometer)80.467199999999991, kilometers);
                Assert.AreEqual("80.4672 km", kilometers.ToString(CultureInfo.InvariantCulture));

                speed = miles / (Hour)duration;
                Assert.AreEqual((MPH)100.0, speed);
                Assert.AreEqual("100 mph", speed.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual("160.9344 km/h", ((Kilometer_Hour)speed).ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual("44.704 m/s", ((Meter_Sec)speed).ToString(CultureInfo.InvariantCulture));
            }