Skip to content

Commit

Permalink
Fixes #2691 concentration parameter must be created with can be varie…
Browse files Browse the repository at this point in the history
…d false (#2737)
  • Loading branch information
msevestre authored Sep 7, 2023
1 parent 4d18dec commit 68391d1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/PKSim.Core/Model/ParameterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ public IParameter CreateConcentrationParameterIn(IFormulaCache formulaCache)
{
var parameter = CreateFor(CoreConstants.Parameters.CONCENTRATION, PKSimBuildingBlockType.Simulation);
parameter.BuildMode = ParameterBuildMode.Local;
parameter.Info.Visible = false;
parameter.Visible = false;
parameter.Formula = _formulaFactory.ConcentrationFormulaFor(formulaCache);
parameter.Dimension = _dimensionRepository.MolarConcentration;
parameter.CanBeVaried = false;
parameter.CanBeVariedInPopulation = false;
parameter.DisplayUnit = _displayUnitRetriever.PreferredUnitFor(parameter);
return parameter;
}
Expand Down
51 changes: 45 additions & 6 deletions tests/PKSim.Tests/Core/ParameterFactorySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using PKSim.Core.Model;
using PKSim.Core.Repositories;
using PKSim.Core.Services;
using DistributionType = OSPSuite.Core.Domain.Formulas.DistributionType;
using IDistributionFormulaFactory = PKSim.Core.Model.IDistributionFormulaFactory;
using IFormulaFactory = PKSim.Core.Model.IFormulaFactory;
using IParameterFactory = PKSim.Core.Model.IParameterFactory;
using ParameterFactory = PKSim.Core.Model.ParameterFactory;
Expand All @@ -35,7 +33,7 @@ protected override void Context()
_formulaFactory = A.Fake<IFormulaFactory>();
_dimensionRepository = A.Fake<IDimensionRepository>();
_displayUnitRetriever = A.Fake<IDisplayUnitRetriever>();
_interpolation= new LinearInterpolation();
_interpolation = new LinearInterpolation();
sut = new ParameterFactory(_objectBaseFactory, _formulaFactory, _dimensionRepository, _displayUnitRetriever, _interpolation);
}
}
Expand Down Expand Up @@ -152,7 +150,7 @@ protected override void Context()
_subParameter = A.Fake<IParameter>();
_originData = new OriginData {Age = new OriginDataParameter(40)};
_distributions.Add(new ParameterDistributionMetaData {Distribution = DistributionType.Normal, Age = 20, ValueOrigin = _valueOrigin1});
_distributions.Add(new ParameterDistributionMetaData { Distribution = DistributionType.Normal, Age = 50, ValueOrigin = _valueOrigin2 });
_distributions.Add(new ParameterDistributionMetaData {Distribution = DistributionType.Normal, Age = 50, ValueOrigin = _valueOrigin2});
A.CallTo(() => _formulaFactory.DistributionFor(A<IEnumerable<ParameterDistributionMetaData>>._, _parameter, _originData)).Returns(_distributionFormula);
A.CallTo(() => _objectBaseFactory.CreateDistributedParameter()).Returns(_parameter);
A.CallTo(() => _objectBaseFactory.CreateParameter()).Returns(_subParameter);
Expand Down Expand Up @@ -212,16 +210,57 @@ protected override void Because()
}

[Observation]
public void the_returned_parameter_shoudld_have_a_min_of_zero_and_an_undefined_max()
public void the_returned_parameter_should_have_a_min_of_zero_and_an_undefined_max()
{
_result.MinValue.ShouldBeEqualTo(0);
_result.MaxValue.ShouldBeNull();
}

[Observation]
public void the_returned_parameter_shoudld_have_a_value_set_to_the_default_value()
public void the_returned_parameter_should_have_a_value_set_to_the_default_value()
{
_result.Formula.ShouldBeEqualTo(_formula);
}
}

public class When_creating_a_concentration_parameter : concern_for_ParameterFactory
{
private IFormulaCache _formulaCache;
private IParameter _parameter;
private IFormula _concentrationFormula;

protected override void Context()
{
base.Context();
_formulaCache = new FormulaCache();
_concentrationFormula = A.Fake<IFormula>();
A.CallTo(() => _formulaFactory.ConcentrationFormulaFor(_formulaCache)).Returns(_concentrationFormula);
}

protected override void Because()
{
_parameter = sut.CreateConcentrationParameterIn(_formulaCache);
}

[Observation]
public void should_ensure_that_the_parameter_cannot_be_varied()
{
_parameter.CanBeVaried.ShouldBeFalse();
_parameter.CanBeVariedInPopulation.ShouldBeFalse();
}

[Observation]
public void the_parameter_should_have_the_expected_default_properties()
{
_parameter.BuildMode.ShouldBeEqualTo(ParameterBuildMode.Local);
_parameter.Visible.ShouldBeFalse();
}

[Observation]
public void should_have_set_the_dimension_of_the_parameter_to_be_molar_concentration()
{
_parameter.Dimension.ShouldBeEqualTo(_dimensionRepository.MolarConcentration);
_parameter.Formula.ShouldBeEqualTo(_concentrationFormula);
}
}
}

0 comments on commit 68391d1

Please sign in to comment.