public FormulaType MapFrom(IFormula formula) { if (formula == null) { return(FormulaType.Constant); } if (formula.IsAnImplementationOf <IDistributionFormula>()) { return(FormulaType.Distribution); } if (formula.IsAnImplementationOf <TableFormula>()) { return(FormulaType.Table); } return(formula.IsConstant() ? FormulaType.Constant : FormulaType.Rate); }
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); } }
public DistributionFormulaType MapFrom(IFormula formula) { if (formula == null) { return(DistributionFormulaType.DiscreteDistribution); } if (formula.IsAnImplementationOf <DiscreteDistributionFormula>() || formula.IsConstant()) { return(DistributionFormulaType.DiscreteDistribution); } if (formula.IsAnImplementationOf <UniformDistributionFormula>()) { return(DistributionFormulaType.UniformDistribution); } if (formula.IsAnImplementationOf <NormalDistributionFormula>()) { return(DistributionFormulaType.NormalDistribution); } if (formula.IsAnImplementationOf <LogNormalDistributionFormula>()) { return(DistributionFormulaType.LogNormalDistribution); } throw new MoBiException(AppConstants.Exceptions.UnknownDistributedFormula(formula.GetType())); }
/// <summary> /// Returns true the formula is a table formula with argument otherwise false /// </summary> public static bool IsTableWithXArgument(this IFormula formula) { return(formula.IsAnImplementationOf <TableFormulaWithXArgument>()); }
/// <summary> /// Returns true the formula is a table formula (without offset) otherwise false /// </summary> public static bool IsTable(this IFormula formula) { return(formula.IsAnImplementationOf <TableFormula>()); }
/// <summary> /// Returns true the formula is a dynamic formula otherwise false /// </summary> public static bool IsDynamic(this IFormula formula) { return(formula.IsAnImplementationOf <DynamicFormula>()); }
/// <summary> /// Returns true the formula is an explicit formula otherwise false /// </summary> public static bool IsExplicit(this IFormula formula) { return(formula.IsAnImplementationOf <ExplicitFormula>()); }
/// <summary> /// Returns true the formula is a constant formula otherwise false /// </summary> public static bool IsConstant(this IFormula formula) { return(formula.IsAnImplementationOf <ConstantFormula>()); }
/// <summary> /// Returns true the formula is a black box formula otherwise false /// </summary> public static bool IsBlackBox(this IFormula formula) { return(formula.IsAnImplementationOf <BlackBoxFormula>()); }
/// <summary> /// Returns true the formula is a distributed otherwise false /// </summary> public static bool IsDistributed(this IFormula formula) { return(formula.IsAnImplementationOf <DistributionFormula>()); }
public void Convert(IFormula formula) { if (formula == null) { return; } //this has to be done before converting the formula var conversionFactor = _dimensionMapper.ConversionFactor(formula); _usingDimensionConverter.Convert(formula); if (formula.IsAnImplementationOf <DynamicFormula>()) { return; } if (formula.IsAnImplementationOf <TableFormulaWithOffset>()) { return; } if (formula.IsAnImplementationOf <TableFormulaWithXArgument>()) { return; } foreach (var objectPath in formula.ObjectPaths) { _usingDimensionConverter.Convert(objectPath); } var constantFormula = formula as ConstantFormula; if (constantFormula != null) { constantFormula.Value *= conversionFactor; return; } var tableFormula = formula as TableFormula; if (tableFormula != null) { foreach (var point in tableFormula.AllPoints()) { point.Y *= conversionFactor; } } var explicitFormula = formula as ExplicitFormula; if (explicitFormula == null) { return; } var newFormula = _formulaMapper.NewFormulaFor(explicitFormula.FormulaString); if (string.IsNullOrEmpty(newFormula)) { return; } explicitFormula.FormulaString = newFormula; }
public void should_create_dynamic_sum_formula() { _formula.IsAnImplementationOf <SumFormula>().ShouldBeTrue(); }