// 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.Linq;
using Assembly.Kernel.Model;
using Assembly.Kernel.Model.FmSectionTypes;
using NUnit.Framework;
using Ringtoets.AssemblyTool.Data;
namespace Ringtoets.AssemblyTool.KernelWrapper.TestUtil
{
///
/// Class for asserting combined failure mechanism input.
///
public static class CombinedFailureMechanismSectionsInputAssert
{
///
/// Asserts whether is equal to .
///
/// The original collection of .
/// The actual collection of .
/// Thrown when
/// is not equal to .
public static void AssertCombinedFailureMechanismInput(CombinedAssemblyFailureMechanismInput[] original, FailureMechanismSectionList[] actual)
{
Assert.AreEqual(original.Length, actual.Length);
for (var i = 0; i < original.Length; i++)
{
CombinedAssemblyFailureMechanismInput failureMechanism = original[i];
FailureMechanismSectionList sectionList = actual[i];
Assert.AreEqual(failureMechanism.N, sectionList.FailureMechanism.LengthEffectFactor);
Assert.AreEqual(failureMechanism.FailureMechanismContribution, sectionList.FailureMechanism.FailureProbabilityMarginFactor);
AssertSections(failureMechanism.Sections.ToArray(), sectionList.Results.ToArray());
}
}
private static void AssertSections(CombinedAssemblyFailureMechanismSection[] originalSections, FmSectionWithCategory[] fmSectionWithCategories)
{
Assert.AreEqual(originalSections.Length, fmSectionWithCategories.Length);
Assert.IsTrue(fmSectionWithCategories.All(r => r.GetType() == typeof(FmSectionWithDirectCategory)));
CollectionAssert.AreEqual(originalSections.Select(s => s.SectionStart), fmSectionWithCategories.Select(r => r.SectionStart));
CollectionAssert.AreEqual(originalSections.Select(s => s.SectionEnd), fmSectionWithCategories.Select(r => r.SectionEnd));
CollectionAssert.AreEqual(originalSections.Select(s => ConvertCategoryGroup(s.CategoryGroup)),
fmSectionWithCategories.Select(r => (FmSectionWithDirectCategory)r)
.Select(category => category.Category));
}
private static EFmSectionCategory ConvertCategoryGroup(FailureMechanismSectionAssemblyCategoryGroup categoryGroup)
{
switch (categoryGroup)
{
case FailureMechanismSectionAssemblyCategoryGroup.None:
return EFmSectionCategory.Gr;
case FailureMechanismSectionAssemblyCategoryGroup.NotApplicable:
return EFmSectionCategory.NotApplicable;
case FailureMechanismSectionAssemblyCategoryGroup.Iv:
return EFmSectionCategory.Iv;
case FailureMechanismSectionAssemblyCategoryGroup.IIv:
return EFmSectionCategory.IIv;
case FailureMechanismSectionAssemblyCategoryGroup.IIIv:
return EFmSectionCategory.IIIv;
case FailureMechanismSectionAssemblyCategoryGroup.IVv:
return EFmSectionCategory.IVv;
case FailureMechanismSectionAssemblyCategoryGroup.Vv:
return EFmSectionCategory.Vv;
case FailureMechanismSectionAssemblyCategoryGroup.VIv:
return EFmSectionCategory.VIv;
case FailureMechanismSectionAssemblyCategoryGroup.VIIv:
return EFmSectionCategory.VIIv;
default:
throw new NotSupportedException();
}
}
}
}