示例#1
0
 public void ConvertFromMilesPerHourToMetersPerSecTest()
 {
     var converter = new SpeedConverter(SpeedUnit.MilesPerHour, SpeedUnit.MetersPerSec);
     Assert.AreEqual(0, converter.Convert(0));
     Assert.AreEqual(0.44704, converter.Convert(1));
     Assert.AreEqual(0.89408, converter.Convert(2));
 }
示例#2
0
 public void ConvertFromMetersPerSecToMilesPerHourTest()
 {
     var converter = new SpeedConverter(SpeedUnit.MetersPerSec, SpeedUnit.MilesPerHour);
     Assert.AreEqual(0, converter.Convert(0));
     Assert.AreEqual(2.23693629, converter.Convert(1));
     Assert.AreEqual(4.47387258, converter.Convert(2));
 }
示例#3
0
        public object Convert(ConverterType type, object value)
        {
            switch (type)
            {
            case ConverterType.Temperature:
                _logger.Debug("Temperature converter started");
                return(TemperatureConverter.Convert(value));

            case ConverterType.Speed:
                _logger.Debug("Speed converter started");
                return(SpeedConverter.Convert(value));

            case ConverterType.DegreeToDirection:
                _logger.Debug("Degree to direction converter started");
                return(DegreeToDirectionConverter.Convert(value));

            case ConverterType.Pressure:
                _logger.Debug("Pressure converter started");
                return(PressureConverter.Convert(value));

            default:
                _logger.Error("Unknown converter type");
                return(null);
            }
        }
示例#4
0
        public void ConvertFromMetersPerSecToMilesPerHourTest()
        {
            var converter = new SpeedConverter(SpeedUnit.MetersPerSec, SpeedUnit.MilesPerHour);

            Assert.AreEqual(0, converter.Convert(0));
            Assert.AreEqual(2.23693629, converter.Convert(1));
            Assert.AreEqual(4.47387258, converter.Convert(2));
        }
示例#5
0
        public void ConvertFromMilesPerHourToMetersPerSecTest()
        {
            var converter = new SpeedConverter(SpeedUnit.MilesPerHour, SpeedUnit.MetersPerSec);

            Assert.AreEqual(0, converter.Convert(0));
            Assert.AreEqual(0.44704, converter.Convert(1));
            Assert.AreEqual(0.89408, converter.Convert(2));
        }
        private void OnLocationMessage(LocationMessage locationMessage)
        {
            _longitude       = locationMessage.Longitude;
            _latitude        = locationMessage.Latitude;
            _currentSpeed    = SpeedConverter.ConvertFromMetersPerSecondToMilePerHour(Convert.ToDouble(locationMessage.Speed));
            _deviceHeading   = locationMessage.Heading;
            _headingAccuracy = locationMessage.HeadingAccuracy;

            AddMessageToGPSHistory(locationMessage);
        }
示例#7
0
    public void SpeedConverter_Convert()
    {
        decimal result = SpeedConverter.Convert(SpeedUnit.MeterPerSecond, SpeedUnit.KilometerPerHour, 60);

        Assert.AreEqual(216m, result);

        result = SpeedConverter.Convert(SpeedUnit.MilePerHour, SpeedUnit.KilometerPerHour, 60);
        // 96.560639999999992d
        Assert.AreEqual(96.56064m, result);
    }
示例#8
0
        public void Example()
        {
            double result = SpeedConverter.Convert(
                SpeedUnit.MeterPerSecond, SpeedUnit.KilometerPerHour, 60);

            Assert.AreEqual(216d, result);

            result = SpeedConverter.Convert(
                SpeedUnit.MilePerHour, SpeedUnit.KilometerPerHour, 60);
            Assert.AreEqual(96.560639999999992d, result);
        }
示例#9
0
        protected virtual void SetComboBox()
        {
            var speedDictinary = SpeedConverter.NiceComboboxDataRepresentation();

            comboBox_FromUnit.DataSource    = new BindingSource(speedDictinary, null);
            comboBox_FromUnit.DisplayMember = "Key";
            comboBox_FromUnit.ValueMember   = "Value";

            comboBox_ToUnit.DataSource    = new BindingSource(speedDictinary, null);
            comboBox_ToUnit.DisplayMember = "Key";
            comboBox_ToUnit.ValueMember   = "Value";
        }
        public async Task liveTestSpeedConverter()
        {
            var apiFactory       = new ConverterAPIFactory();
            var tempConverter    = new SpeedConverter(apiFactory);
            var converterRequest = new ConverterRequest {
                fromType = "KilometersPerHour", fromValue = 120, toType = "MilesPerHour"
            };

            var result = await tempConverter.convert(converterRequest).ConfigureAwait(true);

            Assert.Equal(74.56454, result.resultValue);
            Assert.NotEqual(70, result.resultValue);
        }
示例#11
0
        protected virtual void Calculate()
        {
            if (textBox_FromUnit.Text != string.Empty)
            {
                SpeedConverter speedConverter = new SpeedConverter(decimal.Parse(textBox_FromUnit.Text), comboBox_FromUnit.Text.Replace(" ", "_"), comboBox_ToUnit.Text.Replace(" ", "_"));
                textBox_ToUnit.Text = speedConverter.ConvertUnit().ToString(".########");
            }

            else
            {
                return;
            }
        }
            public void WithUnitAndUnitInput(Type targetType, UnitInput inputOptions, object expected)
            {
                var converter = new SpeedConverter
                {
                    Unit      = SpeedUnit.MetresPerSecond,
                    UnitInput = inputOptions
                };

                var length = Speed.FromMetresPerSecond(1.2);
                var actual = converter.Convert(length, targetType, null, CultureInfo.InvariantCulture);

                Assert.AreEqual(expected, actual);
            }
示例#13
0
        public double GetSpeed(Location loc)
        {
            //current speed
            _currentSpeed = SpeedConverter.ToKmH(loc.Speed);
            _speeds.Add(_currentSpeed);

            //Set max speed if needed
            if (_currentSpeed > MaxSpeed)
            {
                MaxSpeed = _currentSpeed;
            }

            return(_currentSpeed);
        }
            public void WithUnitAndSymbolFormat(Type targetType, SymbolFormat format, object expected)
            {
                var converter = new SpeedConverter
                {
                    Unit         = SpeedUnit.MetresPerSecond,
                    UnitInput    = UnitInput.SymbolRequired,
                    SymbolFormat = format
                };

                var length = Speed.FromMetresPerSecond(1.2);
                var actual = converter.Convert(length, targetType, null, CultureInfo.InvariantCulture);

                Assert.AreEqual(expected, actual);
            }
示例#15
0
            public void ValueFormatUnitAndUnitFormat()
            {
                var converter = new SpeedConverter
                {
                    ValueFormat  = "F2",
                    Unit         = SpeedUnit.MillimetresPerSecond,
                    SymbolFormat = SymbolFormat.SignedSuperScript
                };

                var convert = converter.Convert(Speed.FromMetresPerMinute(12.34), typeof(string), null, CultureInfo.InvariantCulture);

                Assert.AreEqual("205.67\u00A0mm⋅s⁻¹", convert);
                Assert.AreEqual(SpeedUnit.MillimetresPerSecond, converter.Unit);
                Assert.AreEqual(UnitInput.SymbolRequired, converter.UnitInput);
            }
示例#16
0
        /// <summary>Convert the numbers to the new unit.</summary>
        /// <param name="numbers">The numbers used in the convertion.</param>
        /// <returns>The result of the convertion execution.</returns>
        /// <exception cref="ArgumentNullException">When numbers is null.</exception>
        /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception>
        public double Convert(double[] numbers)
        {
            base.Validate(numbers);
            double fromValue = numbers[0];

            switch (current.UnitType)
            {
            case UnitType.Length:
                return(LengthConverter.Convert(
                           (LengthUnit)current.FromUnit,
                           (LengthUnit)current.ToUnit,
                           fromValue));

            case UnitType.Mass:
                return(MassConverter.Convert(
                           (MassUnit)current.FromUnit,
                           (MassUnit)current.ToUnit,
                           fromValue));

            case UnitType.Speed:
                return(SpeedConverter.Convert(
                           (SpeedUnit)current.FromUnit,
                           (SpeedUnit)current.ToUnit,
                           fromValue));

            case UnitType.Temperature:
                return(TemperatureConverter.Convert(
                           (TemperatureUnit)current.FromUnit,
                           (TemperatureUnit)current.ToUnit,
                           fromValue));

            case UnitType.Time:
                return(TimeConverter.Convert(
                           (TimeUnit)current.FromUnit,
                           (TimeUnit)current.ToUnit,
                           fromValue));

            case UnitType.Volume:
                return(VolumeConverter.Convert(
                           (VolumeUnit)current.FromUnit,
                           (VolumeUnit)current.ToUnit,
                           fromValue));

            default:
                throw new ArgumentOutOfRangeException("numbers");
            }
        }
示例#17
0
    /// <summary>Convert the numbers to the new unit.</summary>
    /// <param name="numbers">The numbers used in the conversion.</param>
    /// <returns>The result of the conversion execution.</returns>
    /// <exception cref="ArgumentNullException">When numbers is null.</exception>
    /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception>
    public PreciseNumber Evaluate(PreciseNumber[] operands)
    {
        ((IExpression)this).Validate(operands);

        PreciseNumber fromValue = operands[0];

        if (!fromValue.HasValue)
        {
            return(fromValue);
        }

        return(_current.UnitType switch
        {
            UnitType.Length => new PreciseNumber(LengthConverter.Convert((LengthUnit)_current.FromUnit, (LengthUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Mass => new PreciseNumber(MassConverter.Convert((MassUnit)_current.FromUnit, (MassUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Speed => new PreciseNumber(SpeedConverter.Convert((SpeedUnit)_current.FromUnit, (SpeedUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Temperature => new PreciseNumber(TemperatureConverter.Convert((TemperatureUnit)_current.FromUnit, (TemperatureUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Time => new PreciseNumber(TimeConverter.Convert((TimeUnit)_current.FromUnit, (TimeUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Volume => new PreciseNumber(VolumeConverter.Convert((VolumeUnit)_current.FromUnit, (VolumeUnit)_current.ToUnit, fromValue.Value)),
            _ => throw new ArgumentOutOfRangeException(nameof(operands)),
        });
 public void ConvertMetersPerSecondToKilometersPerHour_WhenCalled_ReturnsSpeedInKilometersPerHour(double metersPerSecond, double expectedResult)
 {
     Assert.AreEqual(expectedResult, SpeedConverter.ConvertMetersPerSecondToKilometersPerHour(metersPerSecond));
 }
 public void ConvertMilesPerHourToKilometersPerHour_WhenCalled_ReturnsSpeedInKilometersPerHour(double milesPerHour, double expectedResult)
 {
     Assert.AreEqual(expectedResult, SpeedConverter.ConvertMilesPerHourToKilometersPerHour(milesPerHour));
 }
 public void ParseKilometersPerHourToMilesPerHour_WhenCalled_ReturnsFormatedSpeed(string speedInKilometersPerHour, string expectedResult, int decimalPlaces)
 {
     Assert.AreEqual(expectedResult, SpeedConverter.ParseKilometersPerHourToMilesPerHour(speedInKilometersPerHour, decimalPlaces));
 }
示例#21
0
 static string GenerateDownloadingInfo(StatusInfo statusInfo, string name) =>
 $"Status: {statusInfo.Action} {name} {statusInfo.Progress:#.00}% @ {SpeedConverter.ConvertSpeed(statusInfo.Speed.GetValueOrDefault(0))}";
 public void ParseMilesPerHourToKilometersPerHour_WhenCalledWithNotParseableArgument_ThrowsFormatException(string speedInMilesPerHour)
 {
     Assert.Throws <FormatException>(() => SpeedConverter.ParseMilesPerHourToKilometersPerHour(speedInMilesPerHour));
 }
 // Use this for initialization
 void Start()
 {
     thisSpeedo = this;
 }
示例#24
0
        private void button1_Click(object sender, EventArgs e)
        {
            
            SpeedConverter speed = new SpeedConverter(double.Parse(textBox1.Text));
            #region Same conditions restriction

            if (comboBox1.SelectedItem.ToString() == "Miles per hour" && comboBox2.SelectedItem.ToString() == "Miles per hour")
                comboBox2.SelectedIndex += 1;
            if (comboBox1.SelectedItem.ToString() == "Feets per second" && comboBox2.SelectedItem.ToString() == "Feets per second")
                comboBox2.SelectedIndex += 1;
            if (comboBox1.SelectedItem.ToString() == "Meters per second" && comboBox2.SelectedItem.ToString() == "Meters per second")
                comboBox2.SelectedIndex += 1;
            if (comboBox1.SelectedItem.ToString() == "Kilometers per hour" && comboBox2.SelectedItem.ToString() == "Kilometers per hour")
                comboBox2.SelectedIndex += 1;
            if (comboBox1.SelectedItem.ToString() == "Knots" && comboBox2.SelectedItem.ToString() == "Knots")
                 comboBox2.SelectedIndex = 0;
                
               
                   
            
            
            #endregion
            #region Miles to Value


            if (comboBox1.SelectedItem.ToString() == "Miles per hour" && comboBox2.SelectedItem.ToString() == "Feets per second")
            {
                textBox2.Text = speed.MilesPerHour_FeetsPerSecond.ToString(".####");
            }





            else if (comboBox1.SelectedItem.ToString() == "Miles per hour" && comboBox2.SelectedItem.ToString() == "Meters per second")
            {
                textBox2.Text = speed.MilesPerHour_MetresPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Miles per hour" && comboBox2.SelectedItem.ToString() == "Kilometers per hour")
            {
                textBox2.Text = speed.MilesPerHour_KilometersPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Miles per hour" && comboBox2.SelectedItem.ToString() == "Knots")
            {
                textBox2.Text = speed.MilesPerHour_Knots.ToString(".####");
            }

            #endregion
            #region Feets per second to Value
            else if (comboBox1.SelectedItem.ToString() == "Feets per second" && comboBox2.SelectedItem.ToString() == "Miles per hour")
            {
                textBox2.Text = speed.FeetsPerSecond_MilesPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Feets per second" && comboBox2.SelectedItem.ToString() == "Meters per second")
            {
                textBox2.Text = speed.FeetsPerSecond_MetresPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Feets per second" && comboBox2.SelectedItem.ToString() == "Kilometers per hour")
            {
                textBox2.Text = speed.FeetsPerSecond_KilometersPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Feets per second" && comboBox2.SelectedItem.ToString() == "Knots")
            {
                textBox2.Text = speed.FeetsPerSecond_Knots.ToString(".####");
            }
            #endregion
            #region Meters per second to Value
            else if (comboBox1.SelectedItem.ToString() == "Meters per second" && comboBox2.SelectedItem.ToString() == "Miles per hour")
            {
                textBox2.Text = speed.MetresPerSecond_MilesPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Meters per second" && comboBox2.SelectedItem.ToString() == "Feets per second")
            {
                textBox2.Text = speed.MetresPerSecond_FeetsPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Meters per second" && comboBox2.SelectedItem.ToString() == "Kilometers per hour")
            {
                textBox2.Text = speed.MetresPerSecond_KilometersPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Meters per second" && comboBox2.SelectedItem.ToString() == "Knots")
            {
                textBox2.Text = speed.MetresPerSecond_Knots.ToString(".####");
            }
            #endregion
            #region Kilometers per hour to Value
            else if (comboBox1.SelectedItem.ToString() == "Kilometers per hour" && comboBox2.SelectedItem.ToString() == "Miles per hour")
            {
                textBox2.Text = speed.KilometersPerHour_MilesPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Kilometers per hour" && comboBox2.SelectedItem.ToString() == "Feets per second")
            {
                textBox2.Text = speed.KilometersPerHour_FeetsPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Kilometers per hour" && comboBox2.SelectedItem.ToString() == "Meters per second")
            {
                textBox2.Text = speed.KilometersPerHour_MetresPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Kilometers per hour" && comboBox2.SelectedItem.ToString() == "Knots")
            {
                textBox2.Text = speed.KilometersPerHour_Knots.ToString(".####");
            }
            #endregion
            #region Knots to Value
            else if (comboBox1.SelectedItem.ToString() == "Knots" && comboBox2.SelectedItem.ToString() == "Miles per hour")
            {
                textBox2.Text = speed.Knots_MilesPerHour.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Knots" && comboBox2.SelectedItem.ToString() == "Feets per second")
            {
                textBox2.Text = speed.Knots_FeetsPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Knots" && comboBox2.SelectedItem.ToString() == "Meters per second")
            {
                textBox2.Text = speed.Knots_MetresPerSecond.ToString(".####");
            }
            else if (comboBox1.SelectedItem.ToString() == "Knots" && comboBox2.SelectedItem.ToString() == "Kilometers per hour")
            {
                textBox2.Text = speed.Knots_KilometersPerHour.ToString(".####");
            }

            #endregion
        }
 private void Start()
 {
     thisSpeedo = this;
 }
示例#26
0
        private void Convert(double value)
        {
            switch (SelectedOp)
            {
            case "Length":
            {
                LengthunitConverter unit = new LengthunitConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Mass and Weight":
            {
                MassConverter unit = new MassConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Power":
            {
                PowerConverter unit = new PowerConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Pressure":
            {
                PressureConverter unit = new PressureConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Energy":
            {
                EnergyConveter unit = new EnergyConveter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Temperature":
            {
                TemperatureConverter unit = new TemperatureConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Volume":
            {
                VolumeConverter unit = new VolumeConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Angle":
            {
                AngleConverter unit = new AngleConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Area":
            {
                AreaConverter unit = new AreaConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Speed":
            {
                SpeedConverter unit = new SpeedConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Time":
            {
                TimeunitsConverter unit = new TimeunitsConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }
            }
        }
 public void ConvertKilometersPerHourToMetersPerSecond_WhenCalled_ReturnsSpeedInMetersPerSecond(double kilometersPerHour, double expectedResult)
 {
     Assert.AreEqual(expectedResult, SpeedConverter.ConvertKilometersPerHourToMetersPerSecond(kilometersPerHour));
 }