Beispiel #1
0
        protected double CombineComponentsOfSameType(UnitOfMeasureComponent component, Dictionary <string, UnitOfMeasureComponent> unitOfMeasureComponents, double finalValue, ScalarUnitOfMeasure scalarUnit)
        {
            var existingComponent = unitOfMeasureComponents[scalarUnit.UnitDimension.DomainID];
            var convertedValue    = _converter.Convert(component.Unit, existingComponent.Unit, 1);
            var newPower          = existingComponent.Power + component.Power;

            if (newPower == 0)
            {
                var testPower = Math.Abs(existingComponent.Power) - 1;
                for (var i = testPower; i > 1; --i)
                {
                    convertedValue = _converter.Convert(component.Unit, existingComponent.Unit, convertedValue);
                }
                unitOfMeasureComponents.Remove(scalarUnit.UnitDimension.DomainID);
            }
            else
            {
                unitOfMeasureComponents[scalarUnit.UnitDimension.DomainID] = new UnitOfMeasureComponent(existingComponent.Unit, newPower);
            }

            finalValue = component.Power < 0 ? finalValue / convertedValue : finalValue * convertedValue;
            return(finalValue);
        }
        public void GivenUnitsInTheSameSystemAndOfTheSameTypeWhenConvertThenValueIsConverted()
        {
            var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
            var targetUom = InternalUnitSystemManager.Instance.UnitOfMeasures["in"];

            var value = _unitOfMeasureConverter.Convert(sourceUom, targetUom, 3);

            Assert.AreEqual(36, value, Epsilon);
        }