Skip to content

Commit

Permalink
DisplacementQuantity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan Nielsen committed Oct 20, 2023
1 parent 734872d commit 058b0e1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using GsaAPI;
using GsaGH.Components;
using GsaGH.Helpers.GsaApi;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using GsaGHTests.Helper;
using OasysUnits;
using Xunit;
using LengthUnit = OasysUnits.Units.LengthUnit;

namespace GsaGHTests.Parameters.Results {
[Collection("GrasshopperFixture collection")]
public partial class GsaDisplacementQuantityTests {
[Fact]
public void GsaDisplacementQuantityConstructorTest() {
var apiResult = new Double6(1.1, 2.2, 3.3, 4.4, 5.5, 6.6);
var displacementQuantity = new GsaDisplacementQuantity(apiResult);
Assert.Equal(apiResult.X, displacementQuantity.X.Meters);
Assert.Equal(apiResult.Y, displacementQuantity.Y.Meters);
Assert.Equal(apiResult.Z, displacementQuantity.Z.Meters);

double lPyth = Math.Sqrt((1.1 * 1.1) + (2.2 * 2.2) + (3.3 * 3.3));
Assert.Equal(lPyth, displacementQuantity.Xyz.Meters);

Assert.Equal(apiResult.XX, displacementQuantity.Xx.Radians);
Assert.Equal(apiResult.YY, displacementQuantity.Yy.Radians);
Assert.Equal(apiResult.ZZ, displacementQuantity.Zz.Radians);

double aPyth = Math.Sqrt((4.4 * 4.4) + (5.5 * 5.5) + (6.6 * 6.6));
Assert.Equal(aPyth, displacementQuantity.Xxyyzz.Radians);
}

[Fact]
public void GsaDisplacementQuantityAngleNanTest() {
var apiResult = new Double6(1.1, 2.2, 3.3, double.NaN, double.NaN, double.NaN);
var displacementQuantity = new GsaDisplacementQuantity(apiResult);

Assert.Equal(Angle.Zero, displacementQuantity.Xx);
Assert.Equal(Angle.Zero, displacementQuantity.Yy);
Assert.Equal(Angle.Zero, displacementQuantity.Zz);
Assert.Equal(Angle.Zero, displacementQuantity.Xxyyzz);
}

[Fact]
public void GsaDisplacementQuantityAngleInfinityTest() {
var apiResult = new Double6(1.1, 2.2, 3.3, double.PositiveInfinity, double.NegativeInfinity, double.NaN);
var displacementQuantity = new GsaDisplacementQuantity(apiResult);

Assert.Equal(360, displacementQuantity.Xx.Degrees);
Assert.Equal(-360, displacementQuantity.Yy.Degrees);
Assert.Equal(Angle.Zero, displacementQuantity.Zz);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using GsaAPI;
using GsaGH.Components;
using GsaGH.Helpers.GsaApi;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using GsaGHTests.Helper;
using OasysUnits;
using Xunit;
using LengthUnit = OasysUnits.Units.LengthUnit;

namespace GsaGHTests.Parameters.Results {
public partial class ResultUtilityTests {
[Theory]
[InlineData(2.0, 3.0, 4.0, LengthUnit.Millimeter)]
public void PythagoreanQuadrupleTest(double a, double b, double c, Enum unit) {
IQuantity x = Quantity.From(a, unit);
IQuantity y = Quantity.From(b, unit);
IQuantity z = Quantity.From(c, unit);
IQuantity quantity = ResultUtility.PythagoreanQuadruple(x, y, z, unit);

double pyth = Math.Sqrt((a * a) + (b * b) + (c * c));
IQuantity expected = Quantity.From(pyth, unit);

Assert.Equal(expected.Value, quantity.Value);
Assert.Equal(expected.Unit, quantity.Unit);
Assert.Equal(expected, quantity);
}
}
}

0 comments on commit 058b0e1

Please sign in to comment.