Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaLos committed Nov 16, 2023
1 parent fb08cfb commit 2540357
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> 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<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> 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<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> 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<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> 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<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> 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<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> 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<double> expected = ExpectedAnalysisCaseValues(component);
int positionsCount = 5;

// Act
ReadOnlyCollection<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> resultSet
= result.Member1dDisplacements.ResultSubset(memberIds, positionsCount);

// Assert result values
int i = 0;
foreach (int id in resultSet.Ids) {
Collection<IDisplacement1d> 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<double> expectedP1 = ExpectedCombinationCaseC1Values(component);
int positionsCount = 5;

// Act
ReadOnlyCollection<int> memberIds = result.MemberIds(MemberList);
IResultSubset1d<IDisplacement1d, IDisplacement, ResultVector6<ExtremaKey1d>> resultSet
= result.Member1dDisplacements.ResultSubset(memberIds, positionsCount);

// Assert result values
int i = 0;
foreach (int id in resultSet.Ids) {
Collection<IDisplacement1d> 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<double> 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<double> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<double> XInMillimeter() {
return new List<double>() {
0,
0,
0,
0,
0,
};
}

internal static List<double> YInMillimeter() {
return new List<double>() {
0,
0,
0,
0,
0,
};
}

internal static List<double> ZInMillimeter() {
return new List<double>() {
0.0,
-3.639,
-5.097,
-3.639,
0.0,
};
}

internal static List<double> XyzInMillimeter() {
return new List<double>() {
0.0,
3.639,
5.097,
3.639,
0.0,
};
}

internal static List<double> XxInRadian() {
return new List<double>() {
0,
0,
0,
0,
0,
};
}

internal static List<double> YyInRadian() {
return new List<double>() {
0.002196,
0.001490,
0.0,
-0.001490,
-0.002196,
};
}

internal static List<double> ZzInRadian() {
return new List<double>() {
0,
0,
0,
0,
0,
};
}

internal static List<double> XxyyzzInRadian() {
return new List<double>() {
0.002196,
0.001490,
0.0,
0.001490,
0.002196,
};
}
}
}
Loading

0 comments on commit 2540357

Please sign in to comment.