-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fixes #909 aging data for calculation * Fixes #909 aging data for calculation * Fixes #909 aging data for calculation
- Loading branch information
Showing
10 changed files
with
272 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Data; | ||
using OSPSuite.Core.Domain; | ||
using OSPSuite.Utility.Extensions; | ||
|
||
namespace OSPSuite.R.Domain | ||
{ | ||
public class AgingData | ||
{ | ||
public int[] IndividualIds { get; set; } | ||
public string[] ParameterPaths { get; set; } | ||
public double[] Times { get; set; } | ||
public double[] Values { get; set; } | ||
|
||
public DataTable ToDataTable() | ||
{ | ||
verifyData(); | ||
var dataTable = new DataTable(); | ||
dataTable.AddColumn<int>(Constants.Population.INDIVIDUAL_ID_COLUMN); | ||
dataTable.AddColumn<string>(Constants.Population.PARAMETER_PATH_COLUMN); | ||
dataTable.AddColumn<double>(Constants.Population.TIME_COLUMN); | ||
dataTable.AddColumn<double>(Constants.Population.VALUE_COLUMN); | ||
|
||
|
||
for (var i = 0; i < IndividualIds.Length; i++) | ||
{ | ||
var row = dataTable.NewRow(); | ||
row[Constants.Population.INDIVIDUAL_ID_COLUMN] = IndividualIds[i]; | ||
row[Constants.Population.PARAMETER_PATH_COLUMN] = ParameterPaths[i]; | ||
row[Constants.Population.TIME_COLUMN] = Times[i]; | ||
row[Constants.Population.VALUE_COLUMN] = Values[i]; | ||
dataTable.Rows.Add(row); | ||
} | ||
|
||
return dataTable; | ||
} | ||
|
||
private void verifyData() | ||
{ | ||
if (IndividualIds == null) | ||
raiseUndefinedError("IndividualIds"); | ||
|
||
if (ParameterPaths == null) | ||
raiseUndefinedError("ParameterPaths"); | ||
|
||
if (Times == null) | ||
raiseUndefinedError("Times"); | ||
|
||
if (Values == null) | ||
raiseUndefinedError("Values"); | ||
|
||
if (IndividualIds.Length != ParameterPaths.Length || IndividualIds.Length != Times.Length || IndividualIds.Length != Values.Length) | ||
throw new InvalidArgumentException($"AgingData values do not have the expected length ({IndividualIds.Length})"); | ||
} | ||
|
||
private void raiseUndefinedError(string type) => throw new InvalidArgumentException($"'{type}' is undefined"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Data; | ||
using OSPSuite.BDDHelper; | ||
using OSPSuite.BDDHelper.Extensions; | ||
using OSPSuite.Core.Domain; | ||
using OSPSuite.Core.Extensions; | ||
using OSPSuite.R.Domain; | ||
|
||
namespace OSPSuite.R.Services | ||
{ | ||
public abstract class concern_for_AgingData : ContextSpecification<AgingData> | ||
{ | ||
protected override void Context() | ||
{ | ||
sut = new AgingData(); | ||
} | ||
} | ||
|
||
public class When_converting_an_uninitialized_aging_data_to_data_table : concern_for_AgingData | ||
{ | ||
[Observation] | ||
public void should_thrown_an_exception() | ||
{ | ||
The.Action(() => sut.ToDataTable()).ShouldThrowAn<InvalidArgumentException>(); | ||
} | ||
} | ||
|
||
public class When_converting_an_invalid_aging_data_to_data_table : concern_for_AgingData | ||
{ | ||
protected override void Context() | ||
{ | ||
base.Context(); | ||
sut.IndividualIds = new[] {1, 2}; | ||
sut.ParameterPaths = new[] {"Path1", "Path1"}; | ||
sut.Times = new[] {1.0, 2.0}; | ||
sut.Values = new[] {1.0, 2.0, 3.0}; | ||
} | ||
|
||
[Observation] | ||
public void should_thrown_an_exception() | ||
{ | ||
The.Action(() => sut.ToDataTable()).ShouldThrowAn<InvalidArgumentException>(); | ||
} | ||
} | ||
|
||
public class When_converting_a_valid_aging_data_to_data_table : concern_for_AgingData | ||
{ | ||
private DataTable _dataTable; | ||
|
||
protected override void Context() | ||
{ | ||
base.Context(); | ||
sut.IndividualIds = new[] {1, 2}; | ||
sut.ParameterPaths = new[] {"Path1", "Path2"}; | ||
sut.Times = new[] {1.0, 2.0}; | ||
sut.Values = new[] {3.0, 4.0}; | ||
} | ||
|
||
protected override void Because() | ||
{ | ||
_dataTable = sut.ToDataTable(); | ||
} | ||
|
||
[Observation] | ||
public void should_thrown_an_exception() | ||
{ | ||
_dataTable.Columns.Count.ShouldBeEqualTo(4); | ||
_dataTable.Rows[0].ValueAt<int>(Constants.Population.INDIVIDUAL_ID_COLUMN).ShouldBeEqualTo(1); | ||
_dataTable.Rows[1].ValueAt<int>(Constants.Population.INDIVIDUAL_ID_COLUMN).ShouldBeEqualTo(2); | ||
|
||
_dataTable.Rows[0].ValueAt<string>(Constants.Population.PARAMETER_PATH_COLUMN).ShouldBeEqualTo("Path1"); | ||
_dataTable.Rows[1].ValueAt<string>(Constants.Population.PARAMETER_PATH_COLUMN).ShouldBeEqualTo("Path2"); | ||
|
||
_dataTable.Rows[0].ValueAt<double>(Constants.Population.TIME_COLUMN).ShouldBeEqualTo(1.0); | ||
_dataTable.Rows[1].ValueAt<double>(Constants.Population.TIME_COLUMN).ShouldBeEqualTo(2.0); | ||
|
||
_dataTable.Rows[0].ValueAt<double>(Constants.Population.VALUE_COLUMN).ShouldBeEqualTo(3.0); | ||
_dataTable.Rows[1].ValueAt<double>(Constants.Population.VALUE_COLUMN).ShouldBeEqualTo(4.0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.