コード例 #1
0
        /// <summary>
        /// Method to convert one length to another
        /// </summary>
        /// <param name="unit">defines which unit used</param>
        /// <param name="length">length for conversion</param>
        /// <returns>returns value after calculation</returns>
        public double ConvertLength(LengthUnit unit, double length)
        {
            try
            {
                if (unit.Equals(LengthUnit.FeetToInch))
                {
                    return(length * InchToFeetConstant);
                }

                if (unit.Equals(LengthUnit.YardToInch))
                {
                    return(length * InchToYardConstant);
                }

                if (unit.Equals(LengthUnit.CentimeterToInch))
                {
                    return(length / CentimeterToInchConstant);
                }

                return(length);
            }
            catch (QuantityException e)
            {
                throw new QuantityException(QuantityException.ExceptionType.InvalidData, e.Message);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #2
0
ファイル: UnitGroup.cs プロジェクト: tarinishukla/gcd
 /// <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));
 }
コード例 #3
0
            public void ParamlessConstructedLengthUnit_ShouldBeEqualToMetre()
            {
                // arrange
                var paramlessConstructedLengthUnit = new LengthUnit();
                var metre = LengthUnit.Metre;

                // act
                // assert
                metre.Equals(paramlessConstructedLengthUnit).Should().BeTrue(because: "'LengthUnit.Metre' should be equal 'new LengthUnit()'");
                paramlessConstructedLengthUnit.Equals(metre).Should().BeTrue(because: "'new LengthUnit()' should be equal 'LengthUnit.Metre'");
            }
コード例 #4
0
        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)));
        }