protected override void Context() { base.Context(); _baseDimensionRepresentation = new BaseDimensionRepresentation { TimeExponent = 2 }; }
protected void CreateDimensionFactory() { BaseDimensionRepresentation baseRepresentation = new BaseDimensionRepresentation(); _concentrationDimension = new Dimension(baseRepresentation, "Concentration", "mol"); _volumeDimension = new Dimension(baseRepresentation, "Volume", "l"); _volumeDimension.AddUnit("ml", 0.001, 0); _timeDimension = new Dimension(baseRepresentation, "Time", "min"); _timeDimension.AddUnit("s", 1 / 60.0, 0); _inversedTime = new Dimension(baseRepresentation, "Inversed time", "1/min"); _becquerel = new Dimension(baseRepresentation, "Becquerel", "1/min"); _dimensionFactory = A.Fake <IMoBiDimensionFactory>(); A.CallTo(() => _dimensionFactory.DimensionForUnit("mol")).Returns(_concentrationDimension); A.CallTo(() => _dimensionFactory.DimensionForUnit("ml")).Returns(_volumeDimension); A.CallTo(() => _dimensionFactory.DimensionForUnit("s")).Returns(_timeDimension); A.CallTo(() => _dimensionFactory.DimensionForUnit("1/min")).Returns(_inversedTime); A.CallTo(() => _dimensionFactory.Has(_inversedTime.Name)).Returns(true); A.CallTo(() => _dimensionFactory.Has(_becquerel.Name)).Returns(true); A.CallTo(() => _dimensionFactory.DimensionForUnit("r/h")).Returns(null); A.CallTo(() => _dimensionFactory.DimensionForUnit("")).Throws <Exception>(); A.CallTo(() => _dimensionFactory.Dimension(_becquerel.Name)).Returns(_becquerel); A.CallTo(() => _dimensionFactory.Dimension(_inversedTime.Name)).Returns(_inversedTime); }
private DimensionInformation createDimensionInfoFromBaseRepresentation(BaseDimensionRepresentation baseRepresentation) { return(new DimensionInformation(baseRepresentation.LengthExponent, baseRepresentation.MassExponent, baseRepresentation.TimeExponent, baseRepresentation.ElectricCurrentExponent, baseRepresentation.TemperatureExponent, baseRepresentation.AmountExponent, baseRepresentation.LuminousIntensityExponent)); }
/// <summary> /// Creates the BaseDimensionRepresentation for two BaseDimensionRepresentation (baserep1/baserep2 => substraction of the exponents) /// </summary> private BaseDimensionRepresentation CreateNewBaseDimRepresentation(BaseDimensionRepresentation amountBaseRep, BaseDimensionRepresentation sizeBaseRep) { var baseDimensionRepresentation = new BaseDimensionRepresentation { AmountExponent = amountBaseRep.AmountExponent - sizeBaseRep.AmountExponent, ElectricCurrentExponent = amountBaseRep.ElectricCurrentExponent - sizeBaseRep.ElectricCurrentExponent, LengthExponent = amountBaseRep.LengthExponent - sizeBaseRep.LengthExponent, LuminousIntensityExponent = amountBaseRep.LuminousIntensityExponent - sizeBaseRep.LuminousIntensityExponent, MassExponent = amountBaseRep.MassExponent - sizeBaseRep.MassExponent, TemperatureExponent = amountBaseRep.TemperatureExponent - sizeBaseRep.TemperatureExponent, TimeExponent = amountBaseRep.TimeExponent - sizeBaseRep.TimeExponent }; return(baseDimensionRepresentation); }
private BaseDimensionRepresentation CreateBaseDimRepresentationExponents(IEnumerable<BaseDimensionRepresentation> brList) { var baseDimensionRepresentation = new BaseDimensionRepresentation(); foreach (var br in brList) { baseDimensionRepresentation.AmountExponent += br.AmountExponent; baseDimensionRepresentation.ElectricCurrentExponent += br.ElectricCurrentExponent; baseDimensionRepresentation.LengthExponent += br.LengthExponent; baseDimensionRepresentation.LuminousIntensityExponent += br.LuminousIntensityExponent; baseDimensionRepresentation.MassExponent += br.MassExponent; baseDimensionRepresentation.TemperatureExponent += br.TemperatureExponent; baseDimensionRepresentation.TimeExponent += br.TimeExponent; } return baseDimensionRepresentation; }
private void checkRHSFormula(IParameter parameter, string displayPath) { var rhsFormula = parameter?.RHSFormula; if (rhsFormula == null) { return; } var rhsDimBaseRep = new BaseDimensionRepresentation(parameter.Dimension.BaseRepresentation); rhsDimBaseRep.TimeExponent = rhsDimBaseRep.TimeExponent - 1; if (!Equals(rhsDimBaseRep, rhsFormula.Dimension.BaseRepresentation)) { addWarning(parameter, AppConstants.Validation.RHSDimensionMismatch(displayPath, rhsFormula.Name)); } checkExplicitFormula(parameter, displayPath, rhsDimBaseRep, rhsFormula as ExplicitFormula); }
protected override void Because() { var serializationString = sut.Serialize(_baseDimensionRepresentation, _serializationContext); _deserializedBaseDimensionRepresentation = sut.Deserialize <BaseDimensionRepresentation>(serializationString, _serializationContext); }
private void checkExplicitFormula(IUsingFormula entityUsingFormula, string displayPath, BaseDimensionRepresentation baseDimensionRepresentation, ExplicitFormula explicitFormula) { if (explicitFormula == null) { return; } var dimensionInfos = new List <QuantityDimensionInformation>(); if (isDoubleString(explicitFormula.FormulaString)) { return; } foreach (var objectReference in explicitFormula.ObjectReferences.Where(x => x.Object.Dimension != null)) { var pathDim = explicitFormula.ObjectPaths.Where(path => path.Alias.Equals(objectReference.Alias)).Select(path => path.Dimension).FirstOrDefault(); if (!Equals(objectReference.Object.Dimension, pathDim)) { addWarning(entityUsingFormula, AppConstants.Validation.ReferenceDimensionMissmatch(displayPath, objectReference, pathDim)); } dimensionInfos.Add(new QuantityDimensionInformation(objectReference.Alias, createDimensionInfoFromBaseRepresentation(objectReference.Object.Dimension.BaseRepresentation))); } var(dimInfo, parseSuccess, calculateDimensionSuccess, errorMessage) = _dimensionParser.GetDimensionInformationFor(explicitFormula.FormulaString, dimensionInfos); if (!parseSuccess) { addNotification(NotificationType.Error, entityUsingFormula, errorMessage); return; } if (calculateDimensionSuccess) { if (!dimInfo.AreEquals(createDimensionInfoFromBaseRepresentation(baseDimensionRepresentation))) { addWarning(entityUsingFormula, AppConstants.Validation.FormulaDimensionMismatch(displayPath, explicitFormula.Dimension.Name)); } return; } //ignore some dimension check errors. //Reason: some formulas are written so that dimension exponents cannot be calculated, e.g. //x^y where y is not dimensionless. if (_userSettings.ShowCannotCalcErrors) { addWarning(entityUsingFormula, errorMessage); } }
private void checkExplicitFormula(IUsingFormula entityUsingFormula, string displayPath, BaseDimensionRepresentation baseDimensionRepresentation, ExplicitFormula explicitFormula) { if (explicitFormula == null) { return; } var dimensionInfos = new List <IQuantityDimensionInfo>(); if (isDoubleString(explicitFormula.FormulaString)) { return; } foreach (var objectReference in explicitFormula.ObjectReferences.Where(x => x.Object.Dimension != null)) { var pathDim = explicitFormula.ObjectPaths.Where(path => path.Alias.Equals(objectReference.Alias)).Select(path => path.Dimension).FirstOrDefault(); if (!Equals(objectReference.Object.Dimension, pathDim)) { addWarning(entityUsingFormula, AppConstants.Validation.ReferenceDimensionMissmatch(displayPath, objectReference, pathDim)); } dimensionInfos.Add(new QuantityDimensionInfo(objectReference.Alias, createDimensionInfoFromBaseRepresentation(objectReference.Object.Dimension.BaseRepresentation))); } IFuncParserErrorData ed = new FuncParserErrorData(); var verifyDimension = _dimensionParser.GetDimensionInfoFor(explicitFormula.FormulaString, dimensionInfos, ed); if (!ed.ErrorNumber.Equals(errNumber.err_OK)) { //ignore some dimension check errors. //Reason: some formulas are written so that dimension exponents cannot be calculated, e.g. //x^y where y is not dimensionless. // //In this case, err_CANNOTCALC_DIMENSION is returned. //In all other cases, generate error or warning, depending on the error number returned if (ed.ErrorNumber != errNumber.err_CANNOTCALC_DIMENSION || (_userSettings.ShowCannotCalcErrors && ed.ErrorNumber == errNumber.err_CANNOTCALC_DIMENSION)) { var notificationType = ed.ErrorNumber.IsOneOf(errNumber.err_DIMENSION, errNumber.err_CANNOTCALC_DIMENSION) ? NotificationType.Warning : NotificationType.Error; addNotification(notificationType, entityUsingFormula, ed.Description); } } else if (!verifyDimension.AreEquals(createDimensionInfoFromBaseRepresentation(baseDimensionRepresentation))) { addWarning(entityUsingFormula, AppConstants.Validation.FormulaDimensionMismatch(displayPath, explicitFormula.Dimension.Name)); } }
/// <summary> /// Sets the exponents of a BaseDimensionRepresentation. /// </summary> private BaseDimensionRepresentation SetExponents(UnitDefinition unitDefinition, BaseDimensionRepresentation unitBr, long i) { unitBr.AmountExponent = unitBr.AmountExponent * unitDefinition.getUnit(i).getExponent(); unitBr.ElectricCurrentExponent = unitBr.ElectricCurrentExponent * unitDefinition.getUnit(i).getExponent(); unitBr.LuminousIntensityExponent = unitBr.LuminousIntensityExponent * unitDefinition.getUnit(i).getExponent(); unitBr.MassExponent = unitBr.MassExponent * unitDefinition.getUnit(i).getExponent(); unitBr.LengthExponent = unitBr.LengthExponent * unitDefinition.getUnit(i).getExponent(); unitBr.TimeExponent = unitBr.TimeExponent * unitDefinition.getUnit(i).getExponent(); unitBr.TemperatureExponent = unitBr.TemperatureExponent * unitDefinition.getUnit(i).getExponent(); return(unitBr); }
public IDimension AddDimension(BaseDimensionRepresentation baseRepresentation, string dimensionName, string baseUnitName) { throw new InvalidOperationException("Should never be called"); }