Skip to content

Commit

Permalink
Fixes #1995 setting the value should also create the formula underneath
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre committed May 2, 2023
1 parent 7bada56 commit ae46b73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
13 changes: 5 additions & 8 deletions src/OSPSuite.Core/Domain/Quantity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Core.Domain.UnitSystem;
using OSPSuite.Utility.Exceptions;

namespace OSPSuite.Core.Domain
{
Expand Down Expand Up @@ -31,9 +29,9 @@ public interface IQuantity : IFormulaUsable, IUsingFormula, IWithValueOrigin
QuantityType QuantityType { get; set; }

/// <summary>
/// Returns the <see cref="QuantityType"/> as a string
/// Returns the <see cref="QuantityType" /> as a string
/// </summary>
string QuantityTypeAsString { get; }
string QuantityTypeAsString { get; }

/// <summary>
/// The value in the displayed unit
Expand All @@ -49,6 +47,7 @@ public interface IQuantity : IFormulaUsable, IUsingFormula, IWithValueOrigin
/// The value in the displayed unit
/// </summary>
(double value, bool success) TryGetValue();

/// <summary>
/// Specifies whether negative values are allowed or not for this quantity
/// </summary>
Expand All @@ -73,8 +72,6 @@ public abstract class Quantity : Entity, IQuantity
/// <inheritdoc />
public QuantityType QuantityType { get; set; }



/// <inheritdoc />
public bool NegativeValuesAllowed { get; set; }

Expand Down Expand Up @@ -167,8 +164,8 @@ public double ValueInDisplayUnit
}

return (value, success);

}

public virtual (double value, bool success) TryGetValueInDisplayUnit()
{
var (value, success) = TryGetValue();
Expand Down
8 changes: 7 additions & 1 deletion src/OSPSuite.Core/Domain/WithExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.UnitSystem;

namespace OSPSuite.Core.Domain
Expand All @@ -14,7 +15,12 @@ public static T WithDimension<T>(this T withDimension, IDimension dimension) whe

public static T WithValue<T>(this T withValue, double value) where T : IWithValue
{
withValue.Value = value;
//A using formula for which no formula is defined? We create a constant formula
if (withValue is IUsingFormula usingFormula && usingFormula.Formula == null)
usingFormula.Formula = new ConstantFormula(value);
else
withValue.Value = value;

return withValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ public abstract class concern_for_DistributionFormulaFactory : ContextSpecificat
{
protected IDistributedParameter _distributedParam;
protected IDimension _dim;
protected IObjectBaseFactory _objectBaseFacotry;
protected IObjectBaseFactory _objectBaseFactory;
private Utility.Container.IContainer _container;

protected override void Context()
{
var percentileParam = new Parameter().WithName(Constants.Distribution.PERCENTILE).WithDimension(_dim).WithValue(0.5);
var percentileParam = new Parameter()
.WithName(Constants.Distribution.PERCENTILE)
.WithDimension(_dim)
.WithValue(0.5);

_dim = new Dimension(new BaseDimensionRepresentation(), "dimenion", "unit");
_distributedParam = new DistributedParameter().WithName("P1").WithDimension(_dim);
_distributedParam.Add(percentileParam);
Expand Down Expand Up @@ -105,6 +109,7 @@ protected override void Context()
_distributedParam.Add(_meanParam);
_discreteDistribution = sut.CreateDiscreteDistributionFormulaFor(_distributedParam, _meanParam);
_distributedParam.Formula = _discreteDistribution;
_distributedParam.Percentile = 0.5;
}

protected override void Because()
Expand Down

0 comments on commit ae46b73

Please sign in to comment.