Skip to content

Commit

Permalink
GSAGH-550: test updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SandeepArup committed Dec 20, 2024
1 parent 3085b66 commit 487de55
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 30 deletions.
6 changes: 1 addition & 5 deletions GsaGH/Helpers/Assembly/ModelAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,7 @@ private void ConvertAndAssembleAnalysisTasks(List<GsaAnalysisTask> analysisTasks
ReadOnlyDictionary<int, AnalysisTask> existingTasks = _model.AnalysisTasks();
foreach (GsaAnalysisTask task in analysisTasks) {
if (!existingTasks.Keys.Contains(task.Id)) {
var analysisCases = new Dictionary<int, AnalysisCase>();
foreach (GsaAnalysisCase analysisCase in task.Cases) {
analysisCases.Add(analysisCase.Id, analysisCase.ApiCase);
}
TaskHelper.ImportAnalysisTask(task, analysisCases, ref _model);
TaskHelper.ImportAnalysisTask(task, ref _model);
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;

using GsaAPI;

using GsaGH.Helpers.Assembly;
using GsaGH.Helpers.GsaApi.EnumMappings;
using GsaGH.Helpers.Import;
using GsaGH.Parameters;

using GsaGHTests.Helper;
Expand All @@ -14,6 +16,7 @@
using OasysUnits;

using Rhino.Geometry;
using Rhino.Runtime;

using Xunit;

Expand Down Expand Up @@ -130,5 +133,39 @@ public void TestModelLengthUnit() {

Assert.Equal(LengthUnit.Foot, UnitMapping.GetUnit(m.ApiModel.UiUnits().LengthLarge));
}


[Fact]
public void AnalysisTaskAndCasesCanBeImportedFromSeedModel() {
//seed model to read existing analysis task
var seedModel = new GsaModel();
seedModel.ApiModel.Open(GsaFile.SteelDesignComplex);
List<GsaAnalysisTaskGoo> seedTasks = seedModel.GetAnalysisTasksAndCombinations().Item1;
var analysis = new GsaAnalysis();
foreach (GsaAnalysisTaskGoo task in seedModel.GetAnalysisTasksAndCombinations().Item1) {
analysis.AnalysisTasks.Add(task.Value);
}
//import into new model
var assembly = new ModelAssembly(null, null, null, null, null, null, analysis,
LengthUnit.Meter, Length.Zero, false, null);
var model = new GsaModel(assembly.GetModel());
List<GsaAnalysisTaskGoo> importedTasks = model.GetAnalysisTasksAndCombinations().Item1;

Assert.Equal(importedTasks.Count, seedTasks.Count);
Assert.Equal(importedTasks.Count, seedTasks.Count);
for (int taskId = 0; taskId < importedTasks.Count; taskId++) {
GsaAnalysisTaskGoo seedTask = seedTasks[taskId];
GsaAnalysisTaskGoo importedTask = seedTasks[taskId];
Assert.Equal(importedTask.Value.Cases.Count, seedTask.Value.Cases.Count);
Assert.Equal(importedTask.Value.ApiTask.Type, seedTask.Value.ApiTask.Type);
Assert.Equal(importedTask.Value.ApiTask.Cases, seedTask.Value.ApiTask.Cases);
for (int caseId = 0; caseId < importedTask.Value.Cases.Count; caseId++) {
GsaAnalysisCase seedCase = seedTask.Value.Cases[caseId];
GsaAnalysisCase importedCase = importedTask.Value.Cases[caseId];
Assert.Equal(importedCase.ApiCase.Name, seedCase.ApiCase.Name);
Assert.Equal(importedCase.ApiCase.Description, seedCase.ApiCase.Description);
}
}
}
}
}
16 changes: 5 additions & 11 deletions GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public void ConstructorTest(int id, string name, string description) {
var analysisCase = new GsaAnalysisCase(id, name, description);

Assert.Equal(id, analysisCase.Id);
Assert.Equal(name, analysisCase.Name);
Assert.Equal(description, analysisCase.Definition);
Assert.Equal(name, analysisCase.ApiCase.Name);
Assert.Equal(description, analysisCase.ApiCase.Description);
}

[Fact]
Expand All @@ -27,22 +27,16 @@ public void DuplicateTest() {

Duplicates.AreEqual(original, duplicate);

duplicate.Id = 0;
duplicate.Name = "";
duplicate.Definition = "";

Assert.Equal(1, original.Id);
Assert.Equal("name", original.Name);
Assert.Equal("description", original.Definition);
Assert.Equal("name", original.ApiCase.Name);
Assert.Equal("description", original.ApiCase.Description);
}

[Fact]
public void EmptyConstructorTest() {
var analysisCase = new GsaAnalysisCase();

Assert.Equal(0, analysisCase.Id);
Assert.Null(analysisCase.Name);
Assert.Null(analysisCase.Definition);
Assert.NotNull(analysisCase.ApiCase);
}
}
}
89 changes: 87 additions & 2 deletions GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,95 @@
using GsaGH.Parameters;
using GsaAPI;
using GsaGH.Helpers;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

using GsaGH.Parameters;

using Xunit;

namespace GsaGHTests.Parameters {
[Collection("GrasshopperFixture collection")]
public class GsaAnalysisTaskTest {

public class GsaAnalysisTaskTests {

private GsaModel _model;
public GsaAnalysisTaskTests() {
_model = new GsaModel();
var cases = new Dictionary<int, LoadCase> {
{ 1, new LoadCase() { CaseType= GsaAPI.LoadCaseType.Dead, Name = "DL" } },
{ 3, new LoadCase() {CaseType= GsaAPI.LoadCaseType.Live, Name = "LL" } }
};
_model.ApiModel.SetLoadCases(new ReadOnlyDictionary<int, LoadCase>(cases));
_model.ApiModel.AddGravityLoad(new GravityLoad { Case = 1, EntityList = "all" });
_model.ApiModel.AddGravityLoad(new GravityLoad { Case = 3, EntityList = "all" });
}

private List<GsaAnalysisTask> GsaAnalysisTasksFromSeedModel(bool withCase = false) {
var gsaSeedModel = new GsaModel();
int id = gsaSeedModel.ApiModel.AddAnalysisTask();
if (withCase) {
gsaSeedModel.ApiModel.AddAnalysisCaseToTask(id, "AnyName", "L1");
}
return new List<GsaAnalysisTask>() { new GsaAnalysisTask(id, gsaSeedModel.ApiModel) };
}

[Fact]
public void WhenNoCasesProvidedShouldAddDefaultCaseCreatedFromLoadCase() {
GsaAPI.Model apiModel = _model.ApiModel;
TaskHelper.ImportAnalysisTask(new GsaAnalysisTask(apiModel.AddAnalysisTask(), apiModel), ref apiModel);
AnalysisTask outTask = _model.ApiModel.AnalysisTasks().Last().Value;
//Gsa model has load case at Row(Or Id) 1 and 3
Assert.Equal(1, outTask.Cases[0]);
Assert.Equal(3, outTask.Cases[1]);
}

//[Fact]
//public void AnalysisCasesAreAppendedWhenAnalysisCaseIsAlreadyAttachedToAnotherTask() {
// GsaAPI.Model apiModel = _model.ApiModel;
// int taskId = apiModel.AddAnalysisTask();
// //this will create analysis case with Id = 1
// apiModel.AddAnalysisCaseToTask(taskId, "AnyName", "L1");
// int analysisCaseId = apiModel.AnalysisTasks()[taskId].Cases[0];
// Assert.Equal(1, analysisCaseId);

// //now create another task
// var newTask = new GsaAnalysisTask(apiModel.AddAnalysisTask(), apiModel);
// //and assign same analysis case Id
// newTask.Cases.Add(new GsaAnalysisCase() {
// Id = analysisCaseId,
// ApiCase = new AnalysisCase("AnyName", "L1")
// });

// ReadOnlyDictionary<int, AnalysisTask> ttasks = apiModel.AnalysisTasks();
// TaskHelper.AddAnalysisTask(newTask, ref apiModel);
// ttasks = apiModel.AnalysisTasks();
// Assert.Equal(2, ttasks.Keys.Max());
// int newAnalysCaseId = apiModel.AnalysisTasks()[newTask.Id].Cases[0];
// Assert.Equal(analysisCaseId + 1, newAnalysCaseId);
//}

[Fact]
public void ShouldCreateDefaultTask() {
TaskHelper.CreateDefaultStaticAnalysisTask(ref _model);
Assert.Single(_model.ApiModel.AnalysisTasks());
}

[Fact]
public void ShouldCreateDefaultCaseWhenCaseCountIsZero() {
GsaAPI.Model apiModel = _model.ApiModel;
TaskHelper.ImportAnalysisTask(GsaAnalysisTasksFromSeedModel().First(), ref apiModel);
Assert.Equal(2, apiModel.AnalysisTasks().First().Value.Cases.Count);
}

[Fact]
public void AnalysisCasesWillBeEmptyInAbsenceOfLoadCase() {
var noLoadModel = new GsaModel();
GsaAPI.Model apiModel = noLoadModel.ApiModel;
TaskHelper.ImportAnalysisTask(GsaAnalysisTasksFromSeedModel().First(), ref apiModel);
Assert.Empty(apiModel.AnalysisTasks().First().Value.Cases);
}

[Fact]
public void EmptyConstructorTest() {
var task = new GsaAnalysisTask();
Expand Down
4 changes: 2 additions & 2 deletions GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static void GetModelAnalysisTest() {

Assert.NotNull(caseGoo);
Assert.Equal(1, caseGoo.Value.Id);
Assert.Equal("L1", caseGoo.Value.Definition);
Assert.Equal("DL", caseGoo.Value.Name);
Assert.Equal("L1", caseGoo.Value.ApiCase.Description);
Assert.Equal("DL", caseGoo.Value.ApiCase.Name);

Assert.NotNull(combGoo);
Assert.Equal(1, combGoo.Value.Id);
Expand Down
8 changes: 4 additions & 4 deletions GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void CreateComponentTest() {

Assert.Equal("my Task", output0.Value);
Assert.Equal(0, output1.Value.Id);
Assert.Equal("1.4L1 + 0.8L3", output1.Value.Definition);
Assert.Equal("my Case", output1.Value.Name);
Assert.Equal("1.4L1 + 0.8L3", output1.Value.ApiCase.Description);
Assert.Equal("my Case", output1.Value.ApiCase.Name);
Assert.Equal("Static", output2.Value);
Assert.Equal(1, output3.Value);
}
Expand All @@ -63,8 +63,8 @@ public void GetTaskInfoFromModelTest() {

Assert.Equal("Task 1", output0.Value);
Assert.Equal(1, output1.Value.Id);
Assert.Equal("L1", output1.Value.Definition);
Assert.Equal("DL", output1.Value.Name);
Assert.Equal("L1", output1.Value.ApiCase.Description);
Assert.Equal("DL", output1.Value.ApiCase.Name);
Assert.Equal("Static", output2.Value);
Assert.Equal(1, output3.Value);
}
Expand Down
4 changes: 2 additions & 2 deletions GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void CreateComponentTest() {

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

Assert.Equal("my Case", output.Value.Name);
Assert.Equal("1.4L1 + 0.8L3", output.Value.Definition);
Assert.Equal("my Case", output.Value.ApiCase.Name);
Assert.Equal("1.4L1 + 0.8L3", output.Value.ApiCase.Description);
}
}
}
4 changes: 2 additions & 2 deletions GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void CreateStaticComponentTest() {
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("my Case", output.Value.Cases[0].ApiCase.Name);
Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].ApiCase.Description);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void CreateComponentTest() {

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("my Case", output.Value.Cases[0].ApiCase.Name);
Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].ApiCase.Description);
}
}
}

0 comments on commit 487de55

Please sign in to comment.