Skip to content

Commit

Permalink
Fixes #2552 Export of Expression profile to PKML - include initial co…
Browse files Browse the repository at this point in the history
…nditions (#2554)
  • Loading branch information
rwmcintosh committed Apr 3, 2023
1 parent 8a4d82b commit dbdc8bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ private TBuilder mapBuilderParameter(IParameter parameter)
{
var builderParameter = _objectBaseFactory.Create<TBuilder>();

if (parameter.Formula != null && parameter.Formula.IsCachable())
// Add the formula to the building block formula cache if the formula can be cached
if (isFormulaCachable(parameter))
{
if (!_formulaCache.Contains(parameter.Formula.Name))
_formulaCache.Add(parameter.Formula);

builderParameter.Formula = _formulaCache[parameter.Formula.Name];
// If the parameter value is different from the default value, set the value only and not the formula
// If the parameter value is not different from the default, set the formula only and not the value
// Even if the formula is not be used by the builder parameter, the cache will have the formula available
if (parameter.ValueDiffersFromDefault())
builderParameter.Value = getParameterValue(parameter);
else
builderParameter.Formula = _formulaCache[parameter.Formula.Name];
}
else
{
(builderParameter.Value, _) = parameter.TryGetValue();
builderParameter.Value = getParameterValue(parameter);
}

builderParameter.Name = parameter.Name;
Expand All @@ -64,6 +71,16 @@ private TBuilder mapBuilderParameter(IParameter parameter)
return builderParameter;
}

private static bool isFormulaCachable(IParameter parameter)
{
return parameter.Formula != null && parameter.Formula.IsCachable();
}

private static double getParameterValue(IParameter parameter)
{
return parameter.TryGetValue().value;
}

protected void MapAllParameters(T sourcePKSimBuildingBlock, TBuildingBlock buildingBlock)
{
var allParameters = AllParametersFor(sourcePKSimBuildingBlock);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FakeItEasy;
using System.Linq;
using FakeItEasy;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core;
Expand Down Expand Up @@ -27,7 +28,7 @@ protected override void Context()
_objectPathFactory = new EntityPathResolverForSpecs();
_lazyLoadTask = A.Fake<ILazyLoadTask>();
A.CallTo(() => _objectBaseFactory.Create<ExpressionProfileBuildingBlock>()).Returns(new ExpressionProfileBuildingBlock());
A.CallTo(() => _objectBaseFactory.Create<ExpressionParameter>()).Returns(new ExpressionParameter());
A.CallTo(() => _objectBaseFactory.Create<ExpressionParameter>()).ReturnsLazily(() => new ExpressionParameter());

sut = new ExpressionProfileToExpressionProfileBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask);
}
Expand Down Expand Up @@ -84,13 +85,25 @@ protected override void Context()
Category = "TestCategory",
Description = "TestDescription"
};

_expressionProfile.GetAllChildren<IParameter>().First().Value = 99;
var parameter = _expressionProfile.GetAllChildren<IParameter>().Last();
parameter.Value = 99;
parameter.Formula = null;
}

protected override void Because()
{
_result = sut.MapFrom(_expressionProfile);
}

[Observation]
public void resulting_expression_parameter_should_have_formula_or_value()
{
_result.Count(x => x.Formula == null).ShouldBeEqualTo(2);
_result.Count(x => x.Formula != null).ShouldBeEqualTo(1);
}

[Observation]
public void resulting_building_block_should_have_the_correct_values()
{
Expand All @@ -100,7 +113,7 @@ public void resulting_building_block_should_have_the_correct_values()
_result.MoleculeName.ShouldBeEqualTo("TestEnzyme");
_result.Type.DisplayName.ShouldBeEqualTo("Enzyme");
_result.Type.IconName.ShouldBeEqualTo("Enzyme");
_result.FormulaCache.Count.ShouldBeEqualTo(3);
_result.FormulaCache.Count.ShouldBeEqualTo(2);
}
}
}

0 comments on commit dbdc8bf

Please sign in to comment.