Exemplo n.º 1
0
 public void ConvertOneCubicMeterToCubicFeet()
 {
     Assert.AreEqual(
         CubicCubicFeetToCubicMeeterRelation,
         VolumeConverter.Convert(1, VolumeUnit.CubicMeters, VolumeUnit.CubicFeet),
         Reservoir.Tolerance);
 }
Exemplo n.º 2
0
 public void ConvertTwoCubicMetersToUnknown()
 {
     Assert.AreEqual(
         2,
         VolumeConverter.Convert(2, VolumeUnit.CubicMeters, VolumeUnit.Unknown),
         Reservoir.Tolerance);
 }
        public void l_mm3()
        {
            converter = new VolumeConverter("l", "mm3");
            double valL = 1;
            double valR = 1000 * 1000;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_usquart()
        {
            converter = new VolumeConverter("l", "US quart");
            double valL = 1;
            double valR = 2.11338;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_usgallon()
        {
            converter = new VolumeConverter("l", "US gallon");
            double valL = 1;
            double valR = 0.264172;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_uspint()
        {
            converter = new VolumeConverter("l", "US pint");
            double valL = 1;
            double valR = 2.11337643513819;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_imperialquart()
        {
            converter = new VolumeConverter("l", "imperial quart");
            double valL = 1;
            double valR = 0.879877;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_ft3()
        {
            converter = new VolumeConverter("l", "ft3");
            double valL = 1;
            double valR = 0.0353147;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_in3()
        {
            converter = new VolumeConverter("l", "in3");
            double valL = 1;
            double valR = 61.0237;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Exemplo n.º 10
0
        public ActionResult <IEnumerable <string> > Get(double unitVal, string UnitOfMeasureFrom, string UnitOfMeasureTo)
        {
            double lbValue;
            var    convertor = new VolumeConverter(UnitOfMeasureFrom, UnitOfMeasureTo);

            lbValue = convertor.LeftToRight(unitVal);

            return(new string[] { unitVal.ToString() + " " + UnitOfMeasureFrom, lbValue.ToString() + " " + UnitOfMeasureTo });
        }
        public void l_imperialgallon()
        {
            converter = new VolumeConverter("l", "imperial gallon");
            double valL = 1;
            double valR = 0.219969;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
        public void l_imperialpint()
        {
            converter = new VolumeConverter("l", "imperial pint");
            double valL = 1;
            double valR = 1.75975;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Exemplo n.º 13
0
        public void Test1GallonConvertsTo3Point7Litres()
        {
            // Arrange
            var converter  = new VolumeConverter();
            var inputvalue = 1;

            // Act
            var result = converter.Convert(inputvalue, Volume.Gallon, Volume.Liter);

            // Assert
            Assert.AreEqual(3.78541, result, 0.1);
        }
Exemplo n.º 14
0
        public void Test20GallonConvertsToMillilitres()
        {
            // Arrange
            var converter  = new VolumeConverter();
            var inputvalue = 20;

            // Act
            var result = converter.Convert(inputvalue, Volume.Gallon, Volume.Millilitre);

            // Assert
            Assert.AreEqual(75708.2, result, 0.1);
        }
Exemplo n.º 15
0
        public void Test5LitreConvertsTo1point3Gallon()
        {
            // Arrange
            var converter  = new VolumeConverter();
            var inputvalue = 5;

            // Act
            var result = converter.Convert(inputvalue, Volume.Liter, Volume.Gallon);

            // Assert
            Assert.AreEqual(1.32086, result, 0.1);
        }
Exemplo n.º 16
0
        public void Test1000MililiterConvertsTo1Liter()
        {
            // Arrange
            var converter  = new VolumeConverter();
            var inputvalue = 1000;

            // Act
            var result = converter.Convert(inputvalue, Volume.Millilitre, Volume.Liter);

            // Assert
            Assert.AreEqual(1, result);
        }
Exemplo n.º 17
0
        public void Test5LitreConvertsTo5000Millilitre()
        {
            // Arrange
            var converter  = new VolumeConverter();
            var inputvalue = 5;

            // Act
            var result = converter.Convert(inputvalue, Volume.Liter, Volume.Millilitre);

            // Assert
            Assert.AreEqual(5000, result);
        }
Exemplo n.º 18
0
        public void Test10000MililiterConvertsTo2point6Gallon()
        {
            // Arrange
            var converter  = new VolumeConverter();
            var inputvalue = 10000;

            // Act
            var result = converter.Convert(inputvalue, Volume.Millilitre, Volume.Gallon);

            // Assert
            Assert.AreEqual(2.641721, result, 0.1);
        }
        public async Task liveTestVolumeConverter()
        {
            var apiFactory       = new ConverterAPIFactory();
            var tempConverter    = new VolumeConverter(apiFactory);
            var converterRequest = new ConverterRequest {
                fromType = "CubicCentimeters", fromValue = 1000, toType = "CubicInches"
            };

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

            Assert.Equal(61.02398, result.resultValue);
            Assert.NotEqual(60, result.resultValue);
        }
Exemplo n.º 20
0
        public void UpdateUnitSystem(UnitSystem unitSystem)
        {
            this.unitSystem = unitSystem;
            this.TextBox.Clear();
            if (unitSystem != null)
            {
                string temperature        = "Temperature: \t\t" + TemperatureConverter.GetUnitAsString(unitSystem.TemperatureUnit);
                string pressure           = "Pressure: \t\t\t" + PressureConverter.GetUnitAsString(unitSystem.PressureUnit);
                string massFlowRate       = "Mass Flow Rate: \t\t" + MassFlowRateConverter.GetUnitAsString(unitSystem.MassFlowRateUnit);
                string volumeFlowRate     = "Volume Flow Rate: \t\t" + VolumeFlowRateConverter.GetUnitAsString(unitSystem.VolumeFlowRateUnit);
                string moistureContent    = "Moisture Content: \t\t" + MoistureContentConverter.GetUnitAsString(unitSystem.MoistureContentUnit);
                string relativeHumidity   = "Fraction: \t\t\t" + FractionConverter.GetUnitAsString(unitSystem.FractionUnit);
                string enthalpy           = "Specific Energy: \t\t" + SpecificEnergyConverter.GetUnitAsString(unitSystem.SpecificEnergyUnit);
                string specificHeat       = "Specific Heat: \t\t" + SpecificHeatConverter.GetUnitAsString(unitSystem.SpecificHeatUnit);
                string energy             = "Energy: \t\t\t" + EnergyConverter.GetUnitAsString(unitSystem.EnergyUnit);
                string power              = "Power: \t\t\t" + PowerConverter.GetUnitAsString(unitSystem.PowerUnit);
                string density            = "Density: \t\t\t" + DensityConverter.GetUnitAsString(unitSystem.DensityUnit);
                string dynamicViscosity   = "Dynamic Viscosity: \t\t" + DynamicViscosityConverter.GetUnitAsString(unitSystem.DynamicViscosityUnit);
                string kinematicViscosity = "Kinematic Viscosity: \t" + KinematicViscosityConverter.GetUnitAsString(unitSystem.KinematicViscosityUnit);
                string conductivity       = "Thermal Conductivity: \t" + ThermalConductivityConverter.GetUnitAsString(unitSystem.ThermalConductivityUnit);
                string diffusivity        = "Diffusivity: \t\t" + DiffusivityConverter.GetUnitAsString(unitSystem.DiffusivityUnit);
                string mass   = "Mass: \t\t\t" + MassConverter.GetUnitAsString(unitSystem.MassUnit);
                string length = "Length: \t\t\t" + LengthConverter.GetUnitAsString(unitSystem.LengthUnit);
                string area   = "Area: \t\t\t" + AreaConverter.GetUnitAsString(unitSystem.AreaUnit);
                string volume = "Volume: \t\t\t" + VolumeConverter.GetUnitAsString(unitSystem.VolumeUnit);
                string time   = "Time: \t\t\t" + TimeConverter.GetUnitAsString(unitSystem.TimeUnit);

                this.TextBox.AppendText(temperature + "\r\n");
                this.TextBox.AppendText(pressure + "\r\n");
                this.TextBox.AppendText(massFlowRate + "\r\n");
                this.TextBox.AppendText(volumeFlowRate + "\r\n");
                this.TextBox.AppendText(moistureContent + "\r\n");
                this.TextBox.AppendText(relativeHumidity + "\r\n");
                this.TextBox.AppendText(enthalpy + "\r\n");
                this.TextBox.AppendText(specificHeat + "\r\n");
                this.TextBox.AppendText(energy + "\r\n");
                this.TextBox.AppendText(power + "\r\n");
                this.TextBox.AppendText(density + "\r\n");
                this.TextBox.AppendText(dynamicViscosity + "\r\n");
                this.TextBox.AppendText(kinematicViscosity + "\r\n");
                this.TextBox.AppendText(conductivity + "\r\n");
                this.TextBox.AppendText(diffusivity + "\r\n");
                this.TextBox.AppendText(mass + "\r\n");
                this.TextBox.AppendText(length + "\r\n");
                this.TextBox.AppendText(area + "\r\n");
                this.TextBox.AppendText(volume + "\r\n");
                this.TextBox.AppendText(time);
            }
        }
Exemplo n.º 21
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");
            }
        }
Exemplo n.º 22
0
        public ActionResult ConvertVolume(float?inputvolume, Volume inputunit, Volume outputunit)
        {
            if (ModelState.IsValid && inputvolume.HasValue)
            {
                var converter = new VolumeConverter();
                var result    = converter.Convert(inputvolume.Value, inputunit, outputunit);

                var con = new UnitConverter.Dto.Convert();
                con.outputvolume = result;

                return(View("Index", con));
            }
            else
            {
                return(View("Index"));
            }
        }
Exemplo n.º 23
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)),
        });
Exemplo n.º 24
0
    public void VolumeConverter_Convert()
    {
        decimal result = VolumeConverter.Convert(VolumeUnit.Gallon, VolumeUnit.Quart, 1);

        Assert.AreEqual(4, result);
    }
 public void Cleanup()
 {
     converter = null;
 }
Exemplo n.º 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;
            }
            }
        }
Exemplo n.º 27
0
 public void ConvertOneCubicFeetToCubicMeter()
 {
     Assert.AreEqual(
         1 / CubicCubicFeetToCubicMeeterRelation,
         VolumeConverter.Convert(1, VolumeUnit.CubicFeet, VolumeUnit.CubicMeters));
 }
Exemplo n.º 28
0
 public void ConvertZeroCubicFeetToCubicMeter()
 {
     Assert.AreEqual(
         0,
         VolumeConverter.Convert(0, VolumeUnit.CubicFeet, VolumeUnit.CubicMeters));
 }
Exemplo n.º 29
0
 public void ConvertTwoCubicFeetsToCubicFeet()
 {
     Assert.AreEqual(2,
                     VolumeConverter.Convert(2, VolumeUnit.CubicFeet, VolumeUnit.CubicFeet),
                     Reservoir.Tolerance);
 }