Skip to content

Commit

Permalink
GSAGH-478 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilman Reinhardt committed May 15, 2024
1 parent 0dd90d3 commit 6a82d05
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
4 changes: 0 additions & 4 deletions GsaGH/Components/4_Analysis/CreateAnalysisTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ protected override void SolveInternal(IGH_DataAccess da) {
break;
}
break;

default:
this.AddRuntimeWarning("It is currently not possible to create Analysis Tasks of type " + _type);
break;
}

var gsaAnalysisTask = new GsaAnalysisTask() {
Expand Down
1 change: 0 additions & 1 deletion GsaGH/Components/6_Display/Preview3dSections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using GsaGH.Helpers.Assembly;
using GsaGH.Helpers.GH;
using GsaGH.Helpers.Graphics;
using GsaGH.Helpers.GsaApi.EnumMappings;
using GsaGH.Parameters;
using GsaGH.Properties;
using OasysGH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void CreateComponentTest() {
Assert.Equal("1.4L1 + 0.8L3", output1.Value.Definition);
Assert.Equal("my Case", output1.Value.Name);
Assert.Equal("Static", output2.Value);
Assert.Equal(0, output3.Value);
Assert.Equal(1, output3.Value);
}

[Fact]
Expand Down
82 changes: 73 additions & 9 deletions GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using GsaGH.Components;
using System;
using Grasshopper.Kernel;
using GsaGH.Components;
using GsaGH.Parameters;
using GsaGHTests.Helpers;
using OasysGH.Components;
Expand All @@ -7,10 +9,11 @@
namespace GsaGHTests.Components.Analysis {
[Collection("GrasshopperFixture collection")]
public class CreateAnalysisTaskTests {
public static GH_OasysComponent ComponentMother() {
public static GH_OasysDropDownComponent ComponentMother() {
var comp = new CreateAnalysisTask();
comp.CreateAttributes();

ComponentTestHelper.SetInput(comp, 1, 0);
ComponentTestHelper.SetInput(comp, "my Task", 1);
var output = (GsaAnalysisCaseGoo)ComponentTestHelper.GetOutput(
CreateAnalysisCaseTests.ComponentMother());
Expand All @@ -21,27 +24,88 @@ public static GH_OasysComponent ComponentMother() {

[Fact]
public void CreateStaticComponentTest() {
GH_OasysComponent comp = ComponentMother();
GH_OasysDropDownComponent comp = ComponentMother();

var output = (GsaAnalysisTaskGoo)ComponentTestHelper.GetOutput(comp);

Assert.Equal(1, output.Value.Id);
Assert.Equal("my Task", output.Value.ApiTask.Name);
Assert.Equal((int)AnalysisTaskType.Static, output.Value.ApiTask.Type);
Assert.Equal("my Case", output.Value.Cases[0].Name);
Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].Definition);
}

[Fact]
public void CreateStaticPDeltaComponentTest() {
GH_OasysComponent comp = ComponentMother();
ComponentTestHelper.SetInput(comp, "my Task", 0);
public void CreateStaticPDeltaComponentTest1() {
var comp = new CreateAnalysisTask();
comp.CreateAttributes();

comp.SetSelected(0, 1);
ComponentTestHelper.SetInput(comp, 1, 0);
ComponentTestHelper.SetInput(comp, "my Task", 1);

var output = (GsaAnalysisTaskGoo)ComponentTestHelper.GetOutput(comp);

Assert.Equal(1, output.Value.Id);
Assert.Equal("my Task", output.Value.ApiTask.Name);
Assert.Equal((int)AnalysisTaskType.Static, output.Value.ApiTask.Type);
Assert.Equal("my Case", output.Value.Cases[0].Name);
Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].Definition);
Assert.Equal((int)AnalysisTaskType.StaticPDelta, output.Value.ApiTask.Type);
Assert.Equal(GH_RuntimeMessageLevel.Warning, comp.RuntimeMessageLevel);
Assert.Single(comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning));
}

[Fact]
public void CreateStaticPDeltaComponentTest2() {
var comp = new CreateAnalysisTask();
comp.CreateAttributes();

comp.SetSelected(0, 1);
comp.SetSelected(1, 1);
ComponentTestHelper.SetInput(comp, 1, 0);
ComponentTestHelper.SetInput(comp, "my Task", 1);
ComponentTestHelper.SetInput(comp, "1.2L1 + 1.2L2", 2);

var output = (GsaAnalysisTaskGoo)ComponentTestHelper.GetOutput(comp);

Assert.Equal(1, output.Value.Id);
Assert.Equal("my Task", output.Value.ApiTask.Name);
Assert.Equal((int)AnalysisTaskType.StaticPDelta, output.Value.ApiTask.Type);
Assert.Equal(GH_RuntimeMessageLevel.Warning, comp.RuntimeMessageLevel);
Assert.Single(comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning));
}

[Fact]
public void CreateStaticPDeltaComponentTest3() {
var comp = new CreateAnalysisTask();
comp.CreateAttributes();

comp.SetSelected(0, 1);
comp.SetSelected(1, 2);
ComponentTestHelper.SetInput(comp, 1, 0);
ComponentTestHelper.SetInput(comp, "my Task", 1);
ComponentTestHelper.SetInput(comp, 2, 2);

var output = (GsaAnalysisTaskGoo)ComponentTestHelper.GetOutput(comp);

Assert.Equal(1, output.Value.Id);
Assert.Equal("my Task", output.Value.ApiTask.Name);
Assert.Equal((int)AnalysisTaskType.StaticPDelta, output.Value.ApiTask.Type);
Assert.Equal(GH_RuntimeMessageLevel.Warning, comp.RuntimeMessageLevel);
Assert.Single(comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning));
}

//[Theory]
//[InlineData(3)]
//[InlineData(8)]
//public void ChangeUnitExceptionsEquationTest(int analysisTaskType) {
// var comp = new CreateFaceLoad();
// comp.CreateAttributes();
// comp.SetSelected(0, 3); // Equation
// ComponentTestHelper.SetInput(comp, "All", 1);
// ComponentTestHelper.SetInput(comp, "myLoad", 2);
// ComponentTestHelper.SetInput(comp, "4*x+7*y-z", 7);
// comp.SetSelected(1, i);
// Assert.Throws<ArgumentOutOfRangeException>(() => ComponentTestHelper.GetOutput(comp));
// Assert.Equal(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, comp.RuntimeMessageLevel);
//}
}
}

0 comments on commit 6a82d05

Please sign in to comment.