Index: Riskeer/Common/src/Riskeer.Common.Data/Structures/StructuresCalculationScenario.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Data/Structures/StructuresCalculationScenario.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Data/Structures/StructuresCalculationScenario.cs (revision 654b5e06e3a5e8cd121092ca40e1e1b405ddbce4) @@ -0,0 +1,52 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Core.Common.Base.Data; +using Riskeer.Common.Data.Calculation; + +namespace Riskeer.Common.Data.Structures +{ + /// + /// This class holds the information for a calculation scenario. + /// + public class StructuresCalculationScenario : StructuresCalculation, ICalculationScenario + where T : IStructuresCalculationInput, new() + { + private RoundedDouble contribution; + + /// + /// Creates a new instance of . + /// + public StructuresCalculationScenario() + { + IsRelevant = true; + contribution = new RoundedDouble(4, 1); + } + + public bool IsRelevant { get; set; } + + public RoundedDouble Contribution + { + get => contribution; + set => contribution = value.ToPrecision(contribution.NumberOfDecimalPlaces); + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationScenarioTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationScenarioTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationScenarioTest.cs (revision 654b5e06e3a5e8cd121092ca40e1e1b405ddbce4) @@ -0,0 +1,131 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Data; +using Core.Common.Data.TestUtil; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Data.TestUtil.IllustrationPoints; + +namespace Riskeer.Common.Data.Test.Structures +{ + [TestFixture] + public class StructuresCalculationScenarioTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var scenario = new StructuresCalculationScenario(); + + // Assert + Assert.IsInstanceOf>(scenario); + Assert.IsInstanceOf(scenario); + + Assert.IsTrue(scenario.IsRelevant); + Assert.AreEqual(4, scenario.Contribution.NumberOfDecimalPlaces); + Assert.AreEqual(1.0, scenario.Contribution, scenario.Contribution.GetAccuracy()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void IsRelevant_Always_ReturnsSetValue(bool isRelevant) + { + // Setup + var scenario = new StructuresCalculationScenario(); + + // Call + scenario.IsRelevant = isRelevant; + + // Assert + Assert.AreEqual(isRelevant, scenario.IsRelevant); + } + + [Test] + public void Contribution_Always_ReturnsSetValue() + { + // Setup + var random = new Random(21); + RoundedDouble contribution = random.NextRoundedDouble(); + + var scenario = new StructuresCalculationScenario(); + + // Call + scenario.Contribution = contribution; + + // Assert + Assert.AreEqual(4, scenario.Contribution.NumberOfDecimalPlaces); + Assert.AreEqual(contribution, scenario.Contribution, scenario.Contribution.GetAccuracy()); + } + + [Test] + public void Clone_NotAllPropertiesSet_ReturnsCopiedInstanceWithPropertiesSet() + { + // Setup + StructuresCalculationScenario original = CreateRandomCalculationScenarioWithoutOutput(); + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones); + } + + [Test] + public void Clone_AllPropertiesSet_ReturnsCopiedInstanceWithPropertiesSet() + { + // Setup + StructuresCalculationScenario original = CreateRandomCalculationScenarioWithoutOutput(); + original.Output = CommonTestDataGenerator.GetRandomStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()); + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones); + } + + private static StructuresCalculationScenario CreateRandomCalculationScenarioWithoutOutput() + { + var random = new Random(21); + + var calculation = new StructuresCalculationScenario + { + Name = "A Name", + Comments = + { + Body = "A comment" + }, + IsRelevant = random.NextBoolean(), + Contribution = random.NextRoundedDouble() + }; + + CommonTestDataGenerator.SetRandomDataToStructuresInput(calculation.InputParameters); + + return calculation; + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationTest.cs =================================================================== diff -u -rb70c5fe23fc35933af143bba669d3e2239377307 -r654b5e06e3a5e8cd121092ca40e1e1b405ddbce4 --- Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationTest.cs (.../StructuresCalculationTest.cs) (revision b70c5fe23fc35933af143bba669d3e2239377307) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationTest.cs (.../StructuresCalculationTest.cs) (revision 654b5e06e3a5e8cd121092ca40e1e1b405ddbce4) @@ -222,21 +222,6 @@ return calculation; } - public class TestStructuresCalculation : StructuresCalculation {} - - public class TestStructuresInput : StructuresInputBase - { - public override bool IsStructureInputSynchronized - { - get - { - return true; - } - } - - public override void SynchronizeStructureInput() {} - } - private static IEnumerable GetCalculations() { var outputWithoutGeneralResult = new TestStructuresOutput(); Index: Riskeer/Common/test/Riskeer.Common.Data.TestUtil/CommonCloneAssert.cs =================================================================== diff -u -rc4311504aa83ba59c5a7e80c0e9bc26650986c05 -r654b5e06e3a5e8cd121092ca40e1e1b405ddbce4 --- Riskeer/Common/test/Riskeer.Common.Data.TestUtil/CommonCloneAssert.cs (.../CommonCloneAssert.cs) (revision c4311504aa83ba59c5a7e80c0e9bc26650986c05) +++ Riskeer/Common/test/Riskeer.Common.Data.TestUtil/CommonCloneAssert.cs (.../CommonCloneAssert.cs) (revision 654b5e06e3a5e8cd121092ca40e1e1b405ddbce4) @@ -318,6 +318,23 @@ /// The cloned object. /// Thrown when and /// are not clones. + public static void AreClones(StructuresCalculationScenario original, StructuresCalculationScenario clone) + where TInput : StructuresInputBase, new() + where TStructure : StructureBase, new() + { + Assert.AreEqual(original.Contribution, clone.Contribution); + Assert.AreEqual(original.IsRelevant, clone.IsRelevant); + AreClones((StructuresCalculation) original, clone); + } + + /// + /// Method that asserts whether and + /// are clones. + /// + /// The original object. + /// The cloned object. + /// Thrown when and + /// are not clones. public static void AreClones(CalculationGroup original, CalculationGroup clone) { AreClones((ICalculationBase) original, clone);