From 25403570a19c030e627f6ff9e8ca6b265f466795 Mon Sep 17 00:00:00 2001 From: DominikaLos Date: Thu, 16 Nov 2023 11:28:13 +0100 Subject: [PATCH] added tests --- .../Collections/Member1dDisplacementsTests.cs | 261 ++++++++++++++++++ .../Member1d/Member1dDisplacementsA1.cs | 87 ++++++ .../Member1d/Member1dDisplacementsC1.cs | 87 ++++++ GsaGHTests/3_Components/ComponentsTests.cs | 2 + 4 files changed, 437 insertions(+) create mode 100644 GsaGHTests/1_BaseParameters/5_Results/Collections/Member1dDisplacementsTests.cs create mode 100644 GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsA1.cs create mode 100644 GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsC1.cs diff --git a/GsaGHTests/1_BaseParameters/5_Results/Collections/Member1dDisplacementsTests.cs b/GsaGHTests/1_BaseParameters/5_Results/Collections/Member1dDisplacementsTests.cs new file mode 100644 index 000000000..ee674da79 --- /dev/null +++ b/GsaGHTests/1_BaseParameters/5_Results/Collections/Member1dDisplacementsTests.cs @@ -0,0 +1,261 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using GsaGH.Parameters.Results; +using GsaGHTests.Helper; +using Xunit; + +namespace GsaGHTests.Parameters.Results { + [Collection("GrasshopperFixture collection")] + public class Member1dDisplacementsTests { + + private static readonly string MemberList = "all"; + + [Fact] + public void Member1dDisplacementsMember1dIdsFromAnalysisCaseTest() { + // Assemble + var result = (GsaResult2)GsaResult2Tests.AnalysisCaseResult(GsaFile.SteelDesignSimple, 1); + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, 5); + + // Assert member IDs + var expectedIds = result.Model.Model.Members(MemberList).Keys.OrderBy(x => x).ToList(); + Assert.Equal(expectedIds, resultSet.Ids); + } + + [Fact] + public void Member1dDisplacementsMember1dIdsFromCombinationCaseTest() { + // Assemble + var result = (GsaResult2)GsaResult2Tests.CombinationCaseResult(GsaFile.SteelDesignSimple, 1); + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, 5); + + // Assert member IDs + var expectedIds = result.Model.Model.Members(MemberList).Keys.OrderBy(x => x).ToList(); + Assert.Equal(expectedIds, resultSet.Ids); + } + + [Theory] + [InlineData(ResultVector6HelperEnum.X)] + [InlineData(ResultVector6HelperEnum.Y)] + [InlineData(ResultVector6HelperEnum.Z)] + [InlineData(ResultVector6HelperEnum.Xyz)] + [InlineData(ResultVector6HelperEnum.Xx)] + [InlineData(ResultVector6HelperEnum.Yy)] + [InlineData(ResultVector6HelperEnum.Zz)] + [InlineData(ResultVector6HelperEnum.Xxyyzz)] + public void Member1dDisplacementsMaxFromAnalysisCaseTest(ResultVector6HelperEnum component) { + // Assemble + var result = (GsaResult2)GsaResult2Tests.AnalysisCaseResult(GsaFile.SteelDesignSimple, 1); + double expected = ExpectedAnalysisCaseValues(component).Max(); + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, 5); + + // Assert Max in set + double max = TestsResultHelper.ResultsHelper(resultSet, component, true); + Assert.Equal(expected, max); + } + + [Theory] + [InlineData(ResultVector6HelperEnum.X)] + [InlineData(ResultVector6HelperEnum.Y)] + [InlineData(ResultVector6HelperEnum.Z)] + [InlineData(ResultVector6HelperEnum.Xyz)] + [InlineData(ResultVector6HelperEnum.Xx)] + [InlineData(ResultVector6HelperEnum.Yy)] + [InlineData(ResultVector6HelperEnum.Zz)] + [InlineData(ResultVector6HelperEnum.Xxyyzz)] + public void Member1dDisplacementsMaxFromCombinationCaseTest(ResultVector6HelperEnum component) { + // Assemble + var result = (GsaResult2)GsaResult2Tests.CombinationCaseResult(GsaFile.SteelDesignSimple, 1); + double expected = ExpectedCombinationCaseC1Values(component).Max(); + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, 5); + + // Assert Max in set + double max = TestsResultHelper.ResultsHelper(resultSet, component, true); + Assert.Equal(expected, max); + } + + [Theory] + [InlineData(ResultVector6HelperEnum.X)] + [InlineData(ResultVector6HelperEnum.Y)] + [InlineData(ResultVector6HelperEnum.Z)] + [InlineData(ResultVector6HelperEnum.Xyz)] + [InlineData(ResultVector6HelperEnum.Xx)] + [InlineData(ResultVector6HelperEnum.Yy)] + [InlineData(ResultVector6HelperEnum.Zz)] + [InlineData(ResultVector6HelperEnum.Xxyyzz)] + public void Member1dDisplacementsMinFromAnalysisCaseTest(ResultVector6HelperEnum component) { + // Assemble + var result = (GsaResult2)GsaResult2Tests.AnalysisCaseResult(GsaFile.SteelDesignSimple, 1); + double expected = ExpectedAnalysisCaseValues(component).Min(); + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, 5); + + // Assert Max in set + double min = TestsResultHelper.ResultsHelper(resultSet, component, false); + Assert.Equal(expected, min); + } + + [Theory] + [InlineData(ResultVector6HelperEnum.X)] + [InlineData(ResultVector6HelperEnum.Y)] + [InlineData(ResultVector6HelperEnum.Z)] + [InlineData(ResultVector6HelperEnum.Xyz)] + [InlineData(ResultVector6HelperEnum.Xx)] + [InlineData(ResultVector6HelperEnum.Yy)] + [InlineData(ResultVector6HelperEnum.Zz)] + [InlineData(ResultVector6HelperEnum.Xxyyzz)] + public void Member1dDisplacementsMinFromcombinationCaseTest(ResultVector6HelperEnum component) { + // Assemble + var result = (GsaResult2)GsaResult2Tests.CombinationCaseResult(GsaFile.SteelDesignSimple, 1); + double expected = ExpectedCombinationCaseC1Values(component).Min(); + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, 5); + + // Assert Max in set + double min = TestsResultHelper.ResultsHelper(resultSet, component, false); + Assert.Equal(expected, min); + } + + [Theory] + [InlineData(ResultVector6HelperEnum.X)] + [InlineData(ResultVector6HelperEnum.Y)] + [InlineData(ResultVector6HelperEnum.Z)] + [InlineData(ResultVector6HelperEnum.Xyz)] + [InlineData(ResultVector6HelperEnum.Xx)] + [InlineData(ResultVector6HelperEnum.Yy)] + [InlineData(ResultVector6HelperEnum.Zz)] + [InlineData(ResultVector6HelperEnum.Xxyyzz)] + public void Member1dDisplacementsValuesFromAnalysisCaseTest(ResultVector6HelperEnum component) { + // Assemble + var result = (GsaResult2)GsaResult2Tests.AnalysisCaseResult(GsaFile.SteelDesignSimple, 1); + List expected = ExpectedAnalysisCaseValues(component); + int positionsCount = 5; + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, positionsCount); + + // Assert result values + int i = 0; + foreach (int id in resultSet.Ids) { + Collection displacementQuantity = resultSet.Subset[id]; + + // for analysis case results we expect 4 positions + Assert.Single(displacementQuantity); + var positions = Enumerable.Range(0, positionsCount) + .Select(k => (double)k / (positionsCount - 1)).ToList(); + foreach (double position in positions) { + double x = TestsResultHelper.ResultsHelper(displacementQuantity[0].Results[position], + component); + Assert.Equal(expected[i++], x); + } + } + } + + [Theory] + [InlineData(ResultVector6HelperEnum.X)] + [InlineData(ResultVector6HelperEnum.Y)] + [InlineData(ResultVector6HelperEnum.Z)] + [InlineData(ResultVector6HelperEnum.Xyz)] + [InlineData(ResultVector6HelperEnum.Xx)] + [InlineData(ResultVector6HelperEnum.Yy)] + [InlineData(ResultVector6HelperEnum.Zz)] + [InlineData(ResultVector6HelperEnum.Xxyyzz)] + public void Member1dDisplacementsValuesFromCombinationCaseTest( + ResultVector6HelperEnum component) { + // Assemble + var result = (GsaResult2)GsaResult2Tests.CombinationCaseResult(GsaFile.SteelDesignSimple, 1); + List expectedP1 = ExpectedCombinationCaseC1Values(component); + int positionsCount = 5; + + // Act + ReadOnlyCollection memberIds = result.MemberIds(MemberList); + IResultSubset1d> resultSet + = result.Member1dDisplacements.ResultSubset(memberIds, positionsCount); + + // Assert result values + int i = 0; + foreach (int id in resultSet.Ids) { + Collection displacementQuantity = resultSet.Subset[id]; + + // for C1 case results we expect 1 permutation in the collection + Assert.Single(displacementQuantity); + + var positions = Enumerable.Range(0, positionsCount) + .Select(k => (double)k / (positionsCount - 1)).ToList(); + foreach (double position in positions) { + double perm1 + = TestsResultHelper.ResultsHelper(displacementQuantity[0].Results[position], component); + Assert.Equal(expectedP1[i], perm1); + } + } + } + + private List ExpectedAnalysisCaseValues(ResultVector6HelperEnum component) { + switch (component) { + case ResultVector6HelperEnum.X: return Member1dDisplacementsA1.XInMillimeter(); + + case ResultVector6HelperEnum.Y: return Member1dDisplacementsA1.YInMillimeter(); + + case ResultVector6HelperEnum.Z: return Member1dDisplacementsA1.ZInMillimeter(); + + case ResultVector6HelperEnum.Xyz: return Member1dDisplacementsA1.XyzInMillimeter(); + + case ResultVector6HelperEnum.Xx: return Member1dDisplacementsA1.XxInRadian(); + + case ResultVector6HelperEnum.Yy: return Member1dDisplacementsA1.YyInRadian(); + + case ResultVector6HelperEnum.Zz: return Member1dDisplacementsA1.ZzInRadian(); + + case ResultVector6HelperEnum.Xxyyzz: return Member1dDisplacementsA1.XxyyzzInRadian(); + } + + throw new NotImplementedException(); + } + + private List ExpectedCombinationCaseC1Values(ResultVector6HelperEnum component) { + switch (component) { + case ResultVector6HelperEnum.X: return Member1dDisplacementsC1.XInMillimeter(); + + case ResultVector6HelperEnum.Y: return Member1dDisplacementsC1.YInMillimeter(); + + case ResultVector6HelperEnum.Z: return Member1dDisplacementsC1.ZInMillimeter(); + + case ResultVector6HelperEnum.Xyz: return Member1dDisplacementsC1.XyzInMillimeter(); + + case ResultVector6HelperEnum.Xx: return Member1dDisplacementsC1.XxInRadian(); + + case ResultVector6HelperEnum.Yy: return Member1dDisplacementsC1.YyInRadian(); + + case ResultVector6HelperEnum.Zz: return Member1dDisplacementsC1.ZzInRadian(); + + case ResultVector6HelperEnum.Xxyyzz: return Member1dDisplacementsC1.XxyyzzInRadian(); + } + + throw new NotImplementedException(); + } + } +} diff --git a/GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsA1.cs b/GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsA1.cs new file mode 100644 index 000000000..503eee3fb --- /dev/null +++ b/GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsA1.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; + +namespace GsaGHTests.Parameters.Results { + public class Member1dDisplacementsA1 { + // these are regression tests, the values are taken directly from GSA results + // "Steel_Design_Simplex.gwb" for all members for analysis case A1 with 5 positions + internal static List XInMillimeter() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List YInMillimeter() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List ZInMillimeter() { + return new List() { + 0.0, + -3.639, + -5.097, + -3.639, + 0.0, + }; + } + + internal static List XyzInMillimeter() { + return new List() { + 0.0, + 3.639, + 5.097, + 3.639, + 0.0, + }; + } + + internal static List XxInRadian() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List YyInRadian() { + return new List() { + 0.002196, + 0.001490, + 0.0, + -0.001490, + -0.002196, + }; + } + + internal static List ZzInRadian() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List XxyyzzInRadian() { + return new List() { + 0.002196, + 0.001490, + 0.0, + 0.001490, + 0.002196, + }; + } + } +} diff --git a/GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsC1.cs b/GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsC1.cs new file mode 100644 index 000000000..6b8df1591 --- /dev/null +++ b/GsaGHTests/1_BaseParameters/5_Results/Collections/RegressionValues/Member1d/Member1dDisplacementsC1.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; + +namespace GsaGHTests.Parameters.Results { + public class Member1dDisplacementsC1 { + // these are regression tests, the values are taken directly from GSA results + // "Steel_Design_Simple.gwb" for all members for combination case C1p1 + internal static List XInMillimeter() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List YInMillimeter() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List ZInMillimeter() { + return new List() { + 0.0, + -8.670, + -12.40, + -8.670, + 0.0, + }; + } + + internal static List XyzInMillimeter() { + return new List() { + 0.0, + 8.670, + 12.40, + 8.670, + 0.0, + }; + } + + internal static List XxInRadian() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List YyInRadian() { + return new List() { + 0.005148, + 0.003658, + 67.33E-6, + -0.003658, + -0.005148, + }; + } + + internal static List ZzInRadian() { + return new List() { + 0, + 0, + 0, + 0, + 0, + }; + } + + internal static List XxyyzzInRadian() { + return new List() { + 0.005148, + 0.003658, + 67.33E-6, + 0.003658, + 0.005148, + }; + } + } +} diff --git a/GsaGHTests/3_Components/ComponentsTests.cs b/GsaGHTests/3_Components/ComponentsTests.cs index 98ad0bfa5..6d84d9e6d 100644 --- a/GsaGHTests/3_Components/ComponentsTests.cs +++ b/GsaGHTests/3_Components/ComponentsTests.cs @@ -62,6 +62,7 @@ public class ComponentsTests { [InlineData(typeof(SelectResult), 2)] [InlineData(typeof(SpringReactionForces), 3)] [InlineData(typeof(TotalLoadsAndReactions), 2)] + [InlineData(typeof(Member1dDisplacements), 2)] public void WhenInitialiseDropdowns_ThenDropDownItemsCount_ShouldBeValid( Type t, int expectedListCount) { var obj = (GH_OasysDropDownComponent)Activator.CreateInstance(t); @@ -138,6 +139,7 @@ public void WhenInitialiseDropdowns_ThenDropDownItems_ShouldBeNull(Type t) { [InlineData(typeof(SelectResult), "AnalysisCase", "Combination")] [InlineData(typeof(SpringReactionForces), "kN", "tf", 1)] [InlineData(typeof(TotalLoadsAndReactions), "kN", "tf")] + [InlineData(typeof(Member1dDisplacements), "All", "Min |R|")] public void WhenSetSelected_ThenSelectedItems_ShouldBeValid( Type t, string defaultValue, string firstValue, int index = 0) { var obj = (GH_OasysDropDownComponent)Activator.CreateInstance(t);