// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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 System.Collections.Generic;
using System.Linq;
using Core.Common.Base;
using NUnit.Framework;
namespace Ringtoets.DuneErosion.Data.TestUtil
{
///
/// Test helper for dealing with dune location calculations in .
///
public static class DuneLocationsTestHelper
{
///
/// Gets all the dune location calculations within the that have an output.
///
/// The failure mechanism to retrieve the dune location calculations from.
/// A collection of all dune location calculations that contain an output.
/// Thrown when is null.
public static IEnumerable GetAllDuneLocationCalculationsWithOutput(DuneErosionFailureMechanism failureMechanism)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
return failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.Where(HasDuneLocationCalculationOutput)
.Concat(failureMechanism.CalculationsForMechanismSpecificSignalingNorm.Where(HasDuneLocationCalculationOutput))
.Concat(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.Where(HasDuneLocationCalculationOutput))
.Concat(failureMechanism.CalculationsForLowerLimitNorm.Where(HasDuneLocationCalculationOutput))
.Concat(failureMechanism.CalculationsForFactorizedLowerLimitNorm.Where(HasDuneLocationCalculationOutput))
.ToArray();
}
///
/// Asserts if all the dune location calculations within the have no output.
///
/// The failure mechanism to assert.
/// Thrown when is null.
/// Thrown when any of the dune location calculations within the
/// contains output.
public static void AssertDuneLocationCalculationsHaveNoOutputs(DuneErosionFailureMechanism failureMechanism)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
Assert.True(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.All(calc => !HasDuneLocationCalculationOutput(calc)));
Assert.True(failureMechanism.CalculationsForMechanismSpecificSignalingNorm.All(calc => !HasDuneLocationCalculationOutput(calc)));
Assert.True(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.All(calc => !HasDuneLocationCalculationOutput(calc)));
Assert.True(failureMechanism.CalculationsForLowerLimitNorm.All(calc => !HasDuneLocationCalculationOutput(calc)));
Assert.True(failureMechanism.CalculationsForFactorizedLowerLimitNorm.All(calc => !HasDuneLocationCalculationOutput(calc)));
}
///
/// Sets dummy output for all dune location calculations within .
///
/// The failure mechanism to set the dune location calculation outputs for.
/// Thrown when is null.
public static void SetDuneLocationCalculationOutput(DuneErosionFailureMechanism failureMechanism)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
var random = new Random(39);
SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm, random);
SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificSignalingNorm, random);
SetDuneLocationCalculationOutput(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm, random);
SetDuneLocationCalculationOutput(failureMechanism.CalculationsForLowerLimitNorm, random);
SetDuneLocationCalculationOutput(failureMechanism.CalculationsForFactorizedLowerLimitNorm, random);
}
private static bool HasDuneLocationCalculationOutput(DuneLocationCalculation calculation)
{
return calculation.Output != null;
}
private static void SetDuneLocationCalculationOutput(IEnumerable calculations, Random random)
{
foreach (DuneLocationCalculation duneLocationCalculation in calculations)
{
duneLocationCalculation.Output = new TestDuneLocationCalculationOutput(random.NextDouble(),
random.NextDouble(),
random.NextDouble());
}
}
}
}