Пример #1
0
        public void GivenUnitOfMeasureWhenGetDomainIdThenDomainId()
        {
            _unitOfMeasure.domainID = "Branch";

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);

            Assert.AreEqual("Branch", unitOfMeasure.DomainID);
        }
Пример #2
0
        public void GivenUnitOfMeasureWhenGetUomIdThenUomId()
        {
            _unitOfMeasure.uomID = 5;

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);

            Assert.AreEqual(5, unitOfMeasure.UomId);
        }
Пример #3
0
        public void GivenUnitOfMeasureWhenGetScaleThenScale()
        {
            _unitOfMeasure.scale = 783681;

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);

            Assert.AreEqual(783681, unitOfMeasure.Scale);
        }
Пример #4
0
        public void GivenUnitOfMeasureWhenGetBaseOffsetThenBaseOffset()
        {
            _unitOfMeasure.baseOffset = 5.516;

            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);

            Assert.AreEqual(5.516, unitOfMeasure.BaseOffset);
        }
Пример #5
0
        public void GivenUnitOfMeasureWhenGetPluralThenPluralForCultureIsFound()
        {
            _unitOfMeasure.Name = new[]
            {
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = "de",
                    plural = "Ursprünge"
                },
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = CultureInfoDefault.DefaultCulture,
                    plural = "Origins"
                }
            };

            var culture       = CultureInfo.GetCultureInfo("de");
            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension, culture);

            Assert.AreEqual("Ursprünge", unitOfMeasure.LabelPlural);
        }
Пример #6
0
        public void GivenUnitOfMeasureWhenGetLabelThenLabelForCultureIsFound()
        {
            _unitOfMeasure.Name = new[]
            {
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = "de",
                    label  = "Herkunft"
                },
                new UnitSystemUnitDimensionUnitDimensionRepresentationUnitOfMeasureName
                {
                    locale = CultureInfoDefault.DefaultCulture,
                    label  = "Origin"
                }
            };

            var culture       = CultureInfo.GetCultureInfo("de");
            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension, culture);

            Assert.AreEqual("Herkunft", unitOfMeasure.Label);
        }
        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;
        }
Пример #8
0
        public void GivenUnitDimensionWhenGetUnitDimensionThenUnitDimension()
        {
            var unitOfMeasure = new ScalarUnitOfMeasure(_unitOfMeasure, _unitDimension);

            Assert.AreSame(_unitDimension, unitOfMeasure.UnitDimension);
        }
Пример #9
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);
        }