private static string formulaStringFrom(IFormula formula) { if (formula != null && formula.IsExplicit()) { return(formula.DowncastTo <ExplicitFormula>().FormulaString); } return(string.Empty); }
private void reportFor(IFormula formula, string caption, int noOfTabs) { string formulaString = string.Empty; if (formula.IsAnImplementationOf <ExplicitFormula>()) { formulaString = formula.DowncastTo <ExplicitFormula>().FormulaString; } if (formula.IsAnImplementationOf <ConstantFormula>()) { formulaString = formula.DowncastTo <ConstantFormula>().Value.ToString(); } if (formula.IsAnImplementationOf <TableFormula>()) { formulaString = "<TABLE>"; } _report.AppendFormat("{0}{1}: {2}", tabs(noOfTabs), caption, formulaString); _report.AppendLine(); if (formula.IsAnImplementationOf <TableFormula>()) { reportFor(formula.DowncastTo <TableFormula>(), noOfTabs + 1); } if (_reportFormulaReferences) { reportFormulaReferences(formula, noOfTabs + 1); } if (_reportFormulaObjectPaths) { reportFormulaObjectPaths(formula, noOfTabs + 1); } }
/// <summary> /// Checks that the formula is equivalent for the start value. This includes evaluation of constant formula to a double /// </summary> /// <param name="startValue">The start value to check</param> /// <param name="targetFormula">The formula being evaluated</param> /// <returns>True if the formula is equivalent to the start value formula</returns> public bool HasEquivalentFormula(IStartValue startValue, IFormula targetFormula) { var startValueFormula = startValue.Formula; if (startValueFormula == null && targetFormula == null) { return(true); } if ((startValueFormula == null || startValueFormula.IsConstant()) && targetFormula.IsConstant()) { return(isConstantFormulaEqualToStartValue(startValue, targetFormula.DowncastTo <ConstantFormula>())); } return(_formulaTask.FormulasAreTheSame(startValue.Formula, targetFormula)); }
private ExplicitFormula updateFormulaToAmountBase(IFormula originalFormula, IDimension amountDimension) { ExplicitFormula formulaInAmount; if (originalFormula.IsExplicit()) { formulaInAmount = _cloneManagerForModel.Clone(originalFormula.DowncastTo <ExplicitFormula>()); } else { formulaInAmount = _objectBaseFactory.Create <ExplicitFormula>() .WithFormulaString(originalFormula.Calculate(null).ToString(CultureInfo.InvariantCulture)); } formulaInAmount.Dimension = amountDimension; var volumeAlias = _formulaTask.AddParentVolumeReferenceToFormula(formulaInAmount); formulaInAmount.FormulaString = $"({formulaInAmount.FormulaString})*{volumeAlias}"; return(formulaInAmount); }
public bool FormulasAreTheSame(IFormula firstFormula, IFormula secondFormula) { if (firstFormula == null && secondFormula == null) { return(true); } if (firstFormula == null || secondFormula == null) { return(false); } var firstType = firstFormula.GetType(); var secondType = secondFormula.GetType(); if (firstType != secondType) { return(false); } //nothing more to check for distributed formula or black box formula if (firstFormula.IsDistributed() || firstFormula.IsBlackBox() || firstFormula.IsDynamic()) { return(true); } if (firstFormula.IsConstant()) { var firstConstFormula = firstFormula.DowncastTo <ConstantFormula>(); var secondConstFormula = secondFormula.DowncastTo <ConstantFormula>(); return(firstConstFormula.Value == secondConstFormula.Value); } if (firstFormula.IsExplicit()) { var firstExplicit = firstFormula.DowncastTo <ExplicitFormula>(); var secondExplicit = secondFormula.DowncastTo <ExplicitFormula>(); if (!string.Equals(firstExplicit.FormulaString, secondExplicit.FormulaString)) { return(false); } //check that formula have the same references using the same alias var firstObjectPathCache = new Cache <string, IFormulaUsablePath>(x => x.Alias); firstObjectPathCache.AddRange(firstExplicit.ObjectPaths); var secondObjectPathCache = new Cache <string, IFormulaUsablePath>(x => x.Alias); secondObjectPathCache.AddRange(secondExplicit.ObjectPaths); if (firstObjectPathCache.Count() != secondObjectPathCache.Count()) { return(false); } foreach (var keyValue in firstObjectPathCache.KeyValues) { if (!secondObjectPathCache.Contains(keyValue.Key)) { return(false); } var path = secondObjectPathCache[keyValue.Key]; if (!path.Equals(keyValue.Value)) { return(false); } } } return(true); }
public void should_copy_criteria() { _formula.DowncastTo <DynamicFormula>().Criteria.ShouldOnlyContain(_sumFormulaCriteria); }
public void the_constant_formula_value_should_be_equal_to_the_value_of_the_formula() { _formula.DowncastTo <ConstantFormula>().Value.ShouldBeEqualTo(10); }
public void should_retrieve_the_formula_for_the_rate_and_calculation_method() { _formula.DowncastTo <ExplicitFormula>().FormulaString.ShouldBeEqualTo(_formulaString); }