/// <summary> /// Method to convert one volume to another /// </summary> /// <param name="unit">defines which unit used</param> /// <param name="volume">volume for conversion</param> /// <returns>returns value after calculation</returns> public double ConvertVolumes(VolumeUnit unit, double volume) { try { if (unit.Equals(VolumeUnit.GallonToLiter)) { return(volume * GallonToLiter); } if (unit.Equals(VolumeUnit.LiterToMilliliter)) { return(volume * LiterToMilliliter); } if (unit.Equals(VolumeUnit.MilliliterToLiter)) { return(volume / MilliliterToLiter); } return(volume); } catch (QuantityException e) { throw new QuantityException(QuantityException.ExceptionType.InvalidData, e.Message); } catch (Exception e) { throw e; } }
/// <summary> /// Mainly used for testing /// </summary> /// <param name="other"></param> /// <returns></returns> public bool Equals(UnitGroup other) { return(VolUnit.Equals(other.VolUnit) && ArUnit.Equals(other.ArUnit) && VertUnit.Equals(other.VertUnit) && HorizUnit.Equals(other.HorizUnit)); }
private double Conversion(string MeasurementType, string conversionType, double value) { Length length = new Length(); Weights weights = new Weights(); Volumes volume = new Volumes(); Temperature temperature = new Temperature(); if (MeasurementType == "length") { LengthUnit unit = length.SetUnitAndConvertLength(conversionType); if (unit == LengthUnit.FeetToInch || unit == LengthUnit.YardToInch || unit == LengthUnit.CentimeterToInch) { return(length.ConvertLength(unit, value)); } } if (MeasurementType == "weight") { WeightsUnit unit = weights.SetUnitAndConvertWeights(conversionType); if (unit.Equals(WeightsUnit.KilogramToGrams) || unit.Equals(WeightsUnit.TonneToKilograms)) { return(weights.ConvertWeigths(unit, value)); } } if (MeasurementType == "volume") { VolumeUnit unit = volume.SetUnitAndConvertVolume(conversionType); if (unit.Equals(VolumeUnit.GallonToLiter) || unit.Equals(VolumeUnit.LiterToMilliliter) || unit.Equals(VolumeUnit.MilliliterToLiter)) { return(volume.ConvertVolumes(unit, value)); } } if (MeasurementType == "temperature") { TemperatureUnit unit = temperature.SetUnitAndConvertTemperature(conversionType); if (unit.Equals(TemperatureUnit.CelsiusToFahrenheit)) { return(temperature.ConvertTemperature(unit, value)); } } return(value); }
public void ParamlessConstructedVolumeUnit_ShouldBeEqualToMetre() { // arrange var paramlessConstructedVolumeUnit = new VolumeUnit(); var metre = VolumeUnit.CubicMetre; // act // assert metre.Equals(paramlessConstructedVolumeUnit).Should().BeTrue(because: "'VolumeUnit.CubicMetre' should be equal 'new VolumeUnit()'"); paramlessConstructedVolumeUnit.Equals(metre).Should().BeTrue(because: "'new VolumeUnit()' should be equal 'VolumeUnit.CubicMetre'"); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is MeasurementUnit other && ((CustomUnit == null && other.CustomUnit == null) || (CustomUnit?.Equals(other.CustomUnit) == true)) && ((AreaUnit == null && other.AreaUnit == null) || (AreaUnit?.Equals(other.AreaUnit) == true)) && ((LengthUnit == null && other.LengthUnit == null) || (LengthUnit?.Equals(other.LengthUnit) == true)) && ((VolumeUnit == null && other.VolumeUnit == null) || (VolumeUnit?.Equals(other.VolumeUnit) == true)) && ((WeightUnit == null && other.WeightUnit == null) || (WeightUnit?.Equals(other.WeightUnit) == true)) && ((GenericUnit == null && other.GenericUnit == null) || (GenericUnit?.Equals(other.GenericUnit) == true)) && ((TimeUnit == null && other.TimeUnit == null) || (TimeUnit?.Equals(other.TimeUnit) == true)) && ((Type == null && other.Type == null) || (Type?.Equals(other.Type) == true))); }
public Volume Convert(Volume from, VolumeUnit to) { if (from.Unit.Equals(to)) return new Volume(from.Amount, to); if (from.Unit.Equals(VolumeUnit.Liters) && to.Equals(VolumeUnit.Gallons)) return new Volume(from.Amount * _gals_In_1_Ltr, to); if (from.Unit.Equals(VolumeUnit.Gallons) && to.Equals(VolumeUnit.Liters)) return new Volume(from.Amount / _gals_In_1_Ltr, to); if (from.Unit.Equals(VolumeUnit.Liters) && to.Equals(VolumeUnit.Barrels)) return new Volume(from.Amount * _brls_In_1_Ltr, to); if (from.Unit.Equals(VolumeUnit.Barrels) && to.Equals(VolumeUnit.Liters)) return new Volume(from.Amount / _brls_In_1_Ltr, to); if (from.Unit.Equals(VolumeUnit.Barrels) && to.Equals(VolumeUnit.Gallons)) return new Volume(from.Amount * _gals_In_1_Brl, to); if (from.Unit.Equals(VolumeUnit.Gallons) && to.Equals(VolumeUnit.Barrels)) return new Volume(from.Amount / _gals_In_1_Brl, to); throw new NotImplementedException(); }