From e649a8496dcdf4181e68511431dda7ca9dd3ec01 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Thu, 19 Dec 2024 15:38:16 +0530 Subject: [PATCH 01/15] GSAGH-550: Analysis case is not consistent with the Load case in Gsa_GH --- GsaGH/Components/4_Analysis/AnalyseModel.cs | 10 ++----- .../Components/4_Analysis/AnalysisCaseInfo.cs | 4 +-- .../4_Analysis/CreateAnalysisTask.cs | 7 ++--- GsaGH/Helpers/Assembly/ModelAssembly.cs | 18 ++++-------- GsaGH/Parameters/0_Model/GsaModel.cs | 29 ++++--------------- .../Parameters/4_Analysis/GsaAnalysisCase.cs | 29 ++++++++----------- .../Parameters/4_Analysis/GsaAnalysisTask.cs | 13 ++------- 7 files changed, 31 insertions(+), 79 deletions(-) diff --git a/GsaGH/Components/4_Analysis/AnalyseModel.cs b/GsaGH/Components/4_Analysis/AnalyseModel.cs index 119410d62..9ee3be477 100644 --- a/GsaGH/Components/4_Analysis/AnalyseModel.cs +++ b/GsaGH/Components/4_Analysis/AnalyseModel.cs @@ -222,10 +222,8 @@ protected override void SolveInternal(IGH_DataAccess da) { if (_analysis) { IReadOnlyDictionary gsaTasks = model.ApiModel.AnalysisTasks(); if (gsaTasks.Count < 1) { - var task = new GsaAnalysisTask { - Id = model.ApiModel.AddAnalysisTask(), - }; - task.CreateDefaultCases(model); + int taskId = TaskHelper.CreateDefaultStaticAnalysisTask(ref model); + var task = new GsaAnalysisTask(taskId, model.ApiModel); if (task.Cases == null || task.Cases.Count == 0) { this.AddRuntimeWarning( " Model contains no loads and has not been analysed, but has been assembled."); @@ -233,10 +231,6 @@ protected override void SolveInternal(IGH_DataAccess da) { this.AddRuntimeRemark( " Model contained no Analysis Tasks. Default Task has been created containing " + "all cases found in model"); - foreach (GsaAnalysisCase ca in task.Cases) { - model.ApiModel.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition); - } - gsaTasks = model.ApiModel.AnalysisTasks(); } } diff --git a/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs b/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs index d92672af7..360b20200 100644 --- a/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs +++ b/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs @@ -46,8 +46,8 @@ protected override void SolveInstance(IGH_DataAccess da) { } if (ghTyp.Value is GsaAnalysisCaseGoo goo) { - da.SetData(0, goo.Value.Name); - da.SetData(1, goo.Value.Definition); + da.SetData(0, goo.Value.ApiCase.Name); + da.SetData(1, goo.Value.ApiCase.Description); da.SetData(2, goo.Value.Id); } else { string type = ghTyp.Value.GetType().ToString(); diff --git a/GsaGH/Components/4_Analysis/CreateAnalysisTask.cs b/GsaGH/Components/4_Analysis/CreateAnalysisTask.cs index 4481e4df9..282a3232a 100644 --- a/GsaGH/Components/4_Analysis/CreateAnalysisTask.cs +++ b/GsaGH/Components/4_Analysis/CreateAnalysisTask.cs @@ -249,12 +249,9 @@ private bool GetAnalysisCases(IGH_DataAccess da, string name, out List(); - var footfallAnalysisCase = new GsaAnalysisCase { - Name = name, - Definition = "Footfall", + cases = new List { + new GsaAnalysisCase(name, "Footfall") }; - cases.Add(footfallAnalysisCase); } return true; diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index b4a8154d4..06bcf63ff 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -254,19 +254,11 @@ private void ConvertAndAssembleAnalysisTasks(List analysisTasks ReadOnlyDictionary existingTasks = _model.AnalysisTasks(); foreach (GsaAnalysisTask task in analysisTasks) { if (!existingTasks.Keys.Contains(task.Id)) { - task.Id = _model.AddAnalysisTask(task.ApiTask); - } - - if (task.Cases == null || task.Cases.Count == 0) { - task.CreateDefaultCases(_gsaModel); - } - - if (task.Cases == null) { - continue; - } - - foreach (GsaAnalysisCase ca in task.Cases) { - _model.AddAnalysisCaseToTask(task.Id, ca.Name, ca.Definition); + var analysisCases = new Dictionary(); + foreach (GsaAnalysisCase analysisCase in task.Cases) { + analysisCases.Add(analysisCase.Id, analysisCase.ApiCase); + } + TaskHelper.ImportAnalysisTask(task, analysisCases, ref _model); } } } diff --git a/GsaGH/Parameters/0_Model/GsaModel.cs b/GsaGH/Parameters/0_Model/GsaModel.cs index 5d6937845..cf4a8f33e 100644 --- a/GsaGH/Parameters/0_Model/GsaModel.cs +++ b/GsaGH/Parameters/0_Model/GsaModel.cs @@ -153,40 +153,21 @@ internal void SetUserDefaultUnits() { internal Tuple, List> GetAnalysisTasksAndCombinations() { ReadOnlyDictionary tasks = ApiModel.AnalysisTasks(); - ReadOnlyDictionary loadCases = ApiModel.LoadCases(); + ReadOnlyDictionary analysisCases = ApiModel.AnalysisCases(); var tasksList = new List(); var caseList = new List(); - var caseIDs = new List(); + foreach (KeyValuePair item in tasks) { - var task = new GsaAnalysisTask(item.Key, item.Value, ApiModel); + var task = new GsaAnalysisTask(item.Key, ApiModel); tasksList.Add(new GsaAnalysisTaskGoo(task)); - caseIDs.AddRange(task.Cases.Select(acase => acase.Id)); } - caseIDs.AddRange(GetLoadCases()); - - foreach (int caseId in caseIDs) { - string caseName = ApiModel.AnalysisCaseName(caseId); - if (caseName == string.Empty) { - if (loadCases.ContainsKey(caseId)) { - caseName = loadCases[caseId].Name; - } - if (caseName == string.Empty) { - caseName = "Case " + caseId; - } - } - - string caseDescription = ApiModel.AnalysisCaseDescription(caseId); - if (caseDescription == string.Empty) { - caseDescription = "L" + caseId; - } - + foreach (KeyValuePair item in analysisCases) { caseList.Add( - new GsaAnalysisCaseGoo(new GsaAnalysisCase(caseId, caseName, caseDescription))); + new GsaAnalysisCaseGoo(new GsaAnalysisCase(item.Key, item.Value.Name, item.Value.Description))); } - return new Tuple, List>(tasksList, caseList); } diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs index 7240ea4e9..d463b5d35 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs @@ -1,4 +1,8 @@ -using GsaGH.Helpers; +using System.Xml.Linq; + +using GsaAPI; + +using GsaGH.Helpers; namespace GsaGH.Parameters { /// @@ -6,38 +10,29 @@ namespace GsaGH.Parameters { /// Refer to Analysis cases to read more. /// public class GsaAnalysisCase { - public string Definition { get; set; } - public string Name { get; set; } + public AnalysisCase ApiCase { get; set; } internal int Id { get; set; } = 0; - public GsaAnalysisCase() { } + public GsaAnalysisCase() { ApiCase = new AnalysisCase("", ""); } public GsaAnalysisCase(string name, string description) { - Name = name; - Definition = description; + ApiCase = new AnalysisCase(name, description); } internal GsaAnalysisCase(int id, string name, string description = "") { Id = id; - Name = name; - Definition = description; + ApiCase = new AnalysisCase(name, description); } public GsaAnalysisCase Duplicate() { - return new GsaAnalysisCase(Id, Name, Definition); + return new GsaAnalysisCase(Id, ApiCase.Name, ApiCase.Description); } public override string ToString() { string id = Id == 0 ? string.Empty : "ID:" + Id + " "; string s = string.Empty; - if (Name != null) { - s += " '" + Name + "'"; - } - - if (Definition != null) { - s += " " + Definition; - } - + s += " '" + ApiCase.Name + "'"; + s += " " + ApiCase.Description; return string.Join(" ", id, s).TrimSpaces(); } } diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs index 08cfa6ef3..30ab93259 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs @@ -20,26 +20,19 @@ public GsaAnalysisTask() { Id = 0; } - internal GsaAnalysisTask(int id, AnalysisTask task, Model model) { + internal GsaAnalysisTask(int id, Model model) { Id = id; - foreach (int caseId in task.Cases) { + ApiTask = model.AnalysisTasks()[Id]; + foreach (int caseId in ApiTask.Cases) { string caseName = model.AnalysisCaseName(caseId); string caseDescription = model.AnalysisCaseDescription(caseId); Cases.Add(new GsaAnalysisCase(caseId, caseName, caseDescription)); } - - ApiTask = task; } public override string ToString() { return (Id > 0 ? $"ID:{Id} " : string.Empty) + $"'{ApiTask.Name}' {ApiTask.Type}".Replace("_", " ") .TrimSpaces(); } - - internal void CreateDefaultCases(GsaModel gsaModel) { - Tuple, List> tuple - = gsaModel.GetAnalysisTasksAndCombinations(); - Cases = tuple.Item2.Select(x => x.Value).ToList(); - } } } From 3085b667d769b6028ba7aa58b243468cb8863cd1 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Thu, 19 Dec 2024 15:50:55 +0530 Subject: [PATCH 02/15] GSAGH-550: retrieve cases from API --- GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs index 30ab93259..fb40f8ae0 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using GsaAPI; @@ -23,10 +24,12 @@ public GsaAnalysisTask() { internal GsaAnalysisTask(int id, Model model) { Id = id; ApiTask = model.AnalysisTasks()[Id]; + ReadOnlyDictionary analysisCases = model.AnalysisCases(); foreach (int caseId in ApiTask.Cases) { - string caseName = model.AnalysisCaseName(caseId); - string caseDescription = model.AnalysisCaseDescription(caseId); - Cases.Add(new GsaAnalysisCase(caseId, caseName, caseDescription)); + if (analysisCases.ContainsKey(caseId)) { + AnalysisCase analysisCase = model.AnalysisCases()[caseId]; + Cases.Add(new GsaAnalysisCase(caseId, analysisCase.Name, analysisCase.Description)); + } } } From 487de5517325d325ce913c1e7141b4fdf364994d Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Fri, 20 Dec 2024 19:17:12 +0530 Subject: [PATCH 03/15] GSAGH-550: test updated --- GsaGH/Helpers/Assembly/ModelAssembly.cs | 6 +- .../1_BaseParameters/0_Model/GsaModelTest.cs | 37 ++++++++ .../4_Analysis/GsaAnalysisCaseTest.cs | 16 ++-- .../4_Analysis/GsaAnalysisTaskTest.cs | 89 ++++++++++++++++++- .../0_Model/GetModelAnalysisTests.cs | 4 +- .../4_Analysis/AnalysisTaskInfoTests.cs | 8 +- .../4_Analysis/CreateAnalysisCaseTests.cs | 4 +- .../4_Analysis/CreateAnalysisTaskTests.cs | 4 +- .../CreateAnalysisTaskTests_OBSOLETE.cs | 4 +- 9 files changed, 142 insertions(+), 30 deletions(-) diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index 06bcf63ff..f5174f214 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -254,11 +254,7 @@ private void ConvertAndAssembleAnalysisTasks(List analysisTasks ReadOnlyDictionary existingTasks = _model.AnalysisTasks(); foreach (GsaAnalysisTask task in analysisTasks) { if (!existingTasks.Keys.Contains(task.Id)) { - var analysisCases = new Dictionary(); - foreach (GsaAnalysisCase analysisCase in task.Cases) { - analysisCases.Add(analysisCase.Id, analysisCase.ApiCase); - } - TaskHelper.ImportAnalysisTask(task, analysisCases, ref _model); + TaskHelper.ImportAnalysisTask(task, ref _model); } } } diff --git a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs index 9c7514e13..f8fa9899c 100644 --- a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs +++ b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs @@ -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; @@ -14,6 +16,7 @@ using OasysUnits; using Rhino.Geometry; +using Rhino.Runtime; using Xunit; @@ -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 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 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); + } + } + } } } diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs index 9c1fb4ba5..750833c78 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs @@ -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] @@ -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); } } } diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs index ac5220a3f..4b8eb2085 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs @@ -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 { + { 1, new LoadCase() { CaseType= GsaAPI.LoadCaseType.Dead, Name = "DL" } }, + { 3, new LoadCase() {CaseType= GsaAPI.LoadCaseType.Live, Name = "LL" } } + }; + _model.ApiModel.SetLoadCases(new ReadOnlyDictionary(cases)); + _model.ApiModel.AddGravityLoad(new GravityLoad { Case = 1, EntityList = "all" }); + _model.ApiModel.AddGravityLoad(new GravityLoad { Case = 3, EntityList = "all" }); + } + + private List GsaAnalysisTasksFromSeedModel(bool withCase = false) { + var gsaSeedModel = new GsaModel(); + int id = gsaSeedModel.ApiModel.AddAnalysisTask(); + if (withCase) { + gsaSeedModel.ApiModel.AddAnalysisCaseToTask(id, "AnyName", "L1"); + } + return new List() { 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 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(); diff --git a/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs b/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs index 864269bbd..f8341a134 100644 --- a/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs +++ b/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs @@ -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); diff --git a/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs b/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs index 4745bca15..a8ec2608c 100644 --- a/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs +++ b/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs @@ -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); } @@ -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); } diff --git a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs index 600f1824b..8437ef91e 100644 --- a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs +++ b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs @@ -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); } } } diff --git a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs index 8468376c8..c3bfb8dcf 100644 --- a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs +++ b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs @@ -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] diff --git a/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs b/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs index 5015d2a48..0ba5fd841 100644 --- a/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs +++ b/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs @@ -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); } } } From 03b5bf5894faa875a1c8c7df2d5be5e773eaa6e5 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Fri, 20 Dec 2024 22:57:51 +0530 Subject: [PATCH 04/15] GSAGH-550: test modified --- GsaGH/Helpers/Assembly/ModelAssembly.cs | 5 +- .../Parameters/4_Analysis/GsaAnalysisTask.cs | 9 ++- .../4_Analysis/GsaAnalysisTaskTest.cs | 67 ++++++++++--------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index f5174f214..2f98387ed 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -251,11 +251,8 @@ private void CheckIfModelIsEmpty() { private void ConvertAndAssembleAnalysisTasks(List analysisTasks) { // Set Analysis Tasks in model if (analysisTasks != null) { - ReadOnlyDictionary existingTasks = _model.AnalysisTasks(); foreach (GsaAnalysisTask task in analysisTasks) { - if (!existingTasks.Keys.Contains(task.Id)) { - TaskHelper.ImportAnalysisTask(task, ref _model); - } + task.Id = TaskHelper.ImportAnalysisTask(task, ref _model); } } } diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs index fb40f8ae0..a9b770b0a 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs @@ -24,6 +24,14 @@ public GsaAnalysisTask() { internal GsaAnalysisTask(int id, Model model) { Id = id; ApiTask = model.AnalysisTasks()[Id]; + CreateCases(model); + } + + internal GsaAnalysisTask(AnalysisTask task, Model model) { + ApiTask = task; + CreateCases(model); + } + private void CreateCases(Model model) { ReadOnlyDictionary analysisCases = model.AnalysisCases(); foreach (int caseId in ApiTask.Cases) { if (analysisCases.ContainsKey(caseId)) { @@ -32,7 +40,6 @@ internal GsaAnalysisTask(int id, Model model) { } } } - public override string ToString() { return (Id > 0 ? $"ID:{Id} " : string.Empty) + $"'{ApiTask.Name}' {ApiTask.Type}".Replace("_", " ") .TrimSpaces(); diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs index 4b8eb2085..cc170934f 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs @@ -34,40 +34,40 @@ private List GsaAnalysisTasksFromSeedModel(bool withCase = fals return new List() { new GsaAnalysisTask(id, gsaSeedModel.ApiModel) }; } + private GsaAnalysisTask CreateTask() { + return new GsaAnalysisTask(AnalysisTaskFactory.CreateStaticAnalysisTask("static"), _model.ApiModel); + } + [Fact] public void WhenNoCasesProvidedShouldAddDefaultCaseCreatedFromLoadCase() { - GsaAPI.Model apiModel = _model.ApiModel; - TaskHelper.ImportAnalysisTask(new GsaAnalysisTask(apiModel.AddAnalysisTask(), apiModel), ref apiModel); + TaskHelper.ImportAnalysisTask(CreateTask(), ref _model); 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 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 AnalysisCasesAreAppendedWhenAnalysisCaseIsAlreadyAttachedToAnotherTask() { + int taskId = _model.ApiModel.AddAnalysisTask(); + //this will create analysis case with Id = 1 + _model.ApiModel.AddAnalysisCaseToTask(taskId, "AnyName", "L1"); + int analysisCaseId = _model.ApiModel.AnalysisTasks()[taskId].Cases[0]; + Assert.Equal(1, analysisCaseId); + + //now create another task + GsaAnalysisTask newTask = CreateTask(); + //and assign same analysis case Id + newTask.Cases.Add(new GsaAnalysisCase() { + Id = analysisCaseId, + ApiCase = new AnalysisCase("AnyName", "L1") + }); + + int newTaskId = TaskHelper.ImportAnalysisTask(newTask, ref _model); + Assert.Equal(2, _model.ApiModel.AnalysisTasks().Keys.Max()); + int newAnalysCaseId = _model.ApiModel.AnalysisTasks()[newTaskId].Cases[0]; + Assert.Equal(analysisCaseId + 1, newAnalysCaseId); + } [Fact] public void ShouldCreateDefaultTask() { @@ -78,22 +78,27 @@ public void ShouldCreateDefaultTask() { [Fact] public void ShouldCreateDefaultCaseWhenCaseCountIsZero() { GsaAPI.Model apiModel = _model.ApiModel; - TaskHelper.ImportAnalysisTask(GsaAnalysisTasksFromSeedModel().First(), ref apiModel); + TaskHelper.ImportAnalysisTask(CreateTask(), ref _model); 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); + TaskHelper.ImportAnalysisTask(CreateTask(), ref noLoadModel); + Assert.Empty(noLoadModel.ApiModel.AnalysisTasks().First().Value.Cases); + } + + [Fact] + public void NullTaskWillNotBeImported() { + int TaskId = TaskHelper.ImportAnalysisTask(new GsaAnalysisTask(), ref _model); + Assert.Equal(-1, TaskId); + Assert.Empty(_model.ApiModel.AnalysisTasks()); } [Fact] public void EmptyConstructorTest() { var task = new GsaAnalysisTask(); - Assert.Equal(0, task.Id); Assert.Null(task.ApiTask); Assert.Empty(task.Cases); From 3a5cc76dcac843ee8f00a86a6a797fb151ba5d79 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Sat, 21 Dec 2024 00:50:22 +0530 Subject: [PATCH 05/15] GSAGH-550: some logic restored --- .../Components/4_Analysis/AnalysisCaseInfo.cs | 4 ++-- .../Parameters/4_Analysis/GsaAnalysisCase.cs | 19 ++++++++++++------- .../1_BaseParameters/0_Model/GsaModelTest.cs | 4 ++-- .../4_Analysis/GsaAnalysisCaseTest.cs | 15 ++++----------- .../4_Analysis/GsaAnalysisTaskTest.cs | 5 +---- GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs | 2 +- .../0_Model/GetModelAnalysisTests.cs | 4 ++-- .../4_Analysis/AnalysisTaskInfoTests.cs | 8 ++++---- .../4_Analysis/CreateAnalysisCaseTests.cs | 4 ++-- .../4_Analysis/CreateAnalysisTaskTests.cs | 4 ++-- .../CreateAnalysisTaskTests_OBSOLETE.cs | 4 ++-- 11 files changed, 34 insertions(+), 39 deletions(-) diff --git a/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs b/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs index 360b20200..d92672af7 100644 --- a/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs +++ b/GsaGH/Components/4_Analysis/AnalysisCaseInfo.cs @@ -46,8 +46,8 @@ protected override void SolveInstance(IGH_DataAccess da) { } if (ghTyp.Value is GsaAnalysisCaseGoo goo) { - da.SetData(0, goo.Value.ApiCase.Name); - da.SetData(1, goo.Value.ApiCase.Description); + da.SetData(0, goo.Value.Name); + da.SetData(1, goo.Value.Definition); da.SetData(2, goo.Value.Id); } else { string type = ghTyp.Value.GetType().ToString(); diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs index d463b5d35..0f8ecce80 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs @@ -10,29 +10,34 @@ namespace GsaGH.Parameters { /// Refer to Analysis cases to read more. /// public class GsaAnalysisCase { - public AnalysisCase ApiCase { get; set; } + private AnalysisCase ApiCase { get; set; } internal int Id { get; set; } = 0; - - public GsaAnalysisCase() { ApiCase = new AnalysisCase("", ""); } + public string Definition => ApiCase?.Description; + public string Name => ApiCase?.Name; public GsaAnalysisCase(string name, string description) { ApiCase = new AnalysisCase(name, description); } - internal GsaAnalysisCase(int id, string name, string description = "") { + internal GsaAnalysisCase(int id, string name, string description) { Id = id; ApiCase = new AnalysisCase(name, description); } public GsaAnalysisCase Duplicate() { - return new GsaAnalysisCase(Id, ApiCase.Name, ApiCase.Description); + return new GsaAnalysisCase(Id, Name, Definition); } public override string ToString() { string id = Id == 0 ? string.Empty : "ID:" + Id + " "; string s = string.Empty; - s += " '" + ApiCase.Name + "'"; - s += " " + ApiCase.Description; + if (Name != null) { + s += " '" + Name + "'"; + } + + if (Definition != null) { + s += " " + Definition; + } return string.Join(" ", id, s).TrimSpaces(); } } diff --git a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs index f8fa9899c..06896ee78 100644 --- a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs +++ b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs @@ -162,8 +162,8 @@ public void AnalysisTaskAndCasesCanBeImportedFromSeedModel() { 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); + Assert.Equal(importedCase.Name, seedCase.Name); + Assert.Equal(importedCase.Definition, seedCase.Definition); } } } diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs index 750833c78..10e7d2301 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisCaseTest.cs @@ -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.ApiCase.Name); - Assert.Equal(description, analysisCase.ApiCase.Description); + Assert.Equal(name, analysisCase.Name); + Assert.Equal(description, analysisCase.Definition); } [Fact] @@ -28,15 +28,8 @@ public void DuplicateTest() { Duplicates.AreEqual(original, duplicate); Assert.Equal(1, original.Id); - 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.NotNull(analysisCase.ApiCase); + Assert.Equal("name", original.Name); + Assert.Equal("description", original.Definition); } } } diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs index cc170934f..3cfd369d8 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs @@ -58,10 +58,7 @@ public void AnalysisCasesAreAppendedWhenAnalysisCaseIsAlreadyAttachedToAnotherTa //now create another task GsaAnalysisTask newTask = CreateTask(); //and assign same analysis case Id - newTask.Cases.Add(new GsaAnalysisCase() { - Id = analysisCaseId, - ApiCase = new AnalysisCase("AnyName", "L1") - }); + newTask.Cases.Add(new GsaAnalysisCase("AnyName", "L1")); int newTaskId = TaskHelper.ImportAnalysisTask(newTask, ref _model); Assert.Equal(2, _model.ApiModel.AnalysisTasks().Keys.Max()); diff --git a/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs b/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs index 3369503e8..7fd0477b8 100644 --- a/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs +++ b/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs @@ -57,7 +57,7 @@ public class GhOasysGooTest { [InlineData(typeof(GsaLoadCaseGoo), typeof(GsaLoadCase))] // 4_Analysis - [InlineData(typeof(GsaAnalysisCaseGoo), typeof(GsaAnalysisCase))] + // [InlineData(typeof(GsaAnalysisCaseGoo), typeof(GsaAnalysisCase))] //[InlineData(typeof(GsaAnalysisTaskGoo), typeof(GsaAnalysisTask))] [InlineData(typeof(GsaCombinationCaseGoo), typeof(GsaCombinationCase))] diff --git a/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs b/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs index f8341a134..864269bbd 100644 --- a/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs +++ b/GsaGHTests/3_Components/0_Model/GetModelAnalysisTests.cs @@ -31,8 +31,8 @@ public static void GetModelAnalysisTest() { Assert.NotNull(caseGoo); Assert.Equal(1, caseGoo.Value.Id); - Assert.Equal("L1", caseGoo.Value.ApiCase.Description); - Assert.Equal("DL", caseGoo.Value.ApiCase.Name); + Assert.Equal("L1", caseGoo.Value.Definition); + Assert.Equal("DL", caseGoo.Value.Name); Assert.NotNull(combGoo); Assert.Equal(1, combGoo.Value.Id); diff --git a/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs b/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs index a8ec2608c..4745bca15 100644 --- a/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs +++ b/GsaGHTests/3_Components/4_Analysis/AnalysisTaskInfoTests.cs @@ -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.ApiCase.Description); - Assert.Equal("my Case", output1.Value.ApiCase.Name); + Assert.Equal("1.4L1 + 0.8L3", output1.Value.Definition); + Assert.Equal("my Case", output1.Value.Name); Assert.Equal("Static", output2.Value); Assert.Equal(1, output3.Value); } @@ -63,8 +63,8 @@ public void GetTaskInfoFromModelTest() { Assert.Equal("Task 1", output0.Value); Assert.Equal(1, output1.Value.Id); - Assert.Equal("L1", output1.Value.ApiCase.Description); - Assert.Equal("DL", output1.Value.ApiCase.Name); + Assert.Equal("L1", output1.Value.Definition); + Assert.Equal("DL", output1.Value.Name); Assert.Equal("Static", output2.Value); Assert.Equal(1, output3.Value); } diff --git a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs index 8437ef91e..600f1824b 100644 --- a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs +++ b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisCaseTests.cs @@ -27,8 +27,8 @@ public void CreateComponentTest() { var output = (GsaAnalysisCaseGoo)ComponentTestHelper.GetOutput(comp); - Assert.Equal("my Case", output.Value.ApiCase.Name); - Assert.Equal("1.4L1 + 0.8L3", output.Value.ApiCase.Description); + Assert.Equal("my Case", output.Value.Name); + Assert.Equal("1.4L1 + 0.8L3", output.Value.Definition); } } } diff --git a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs index c3bfb8dcf..8468376c8 100644 --- a/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs +++ b/GsaGHTests/3_Components/4_Analysis/CreateAnalysisTaskTests.cs @@ -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].ApiCase.Name); - Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].ApiCase.Description); + Assert.Equal("my Case", output.Value.Cases[0].Name); + Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].Definition); } [Fact] diff --git a/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs b/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs index 0ba5fd841..5015d2a48 100644 --- a/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs +++ b/GsaGHTests/3_Components/Obsolete/CreateAnalysisTaskTests_OBSOLETE.cs @@ -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].ApiCase.Name); - Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].ApiCase.Description); + Assert.Equal("my Case", output.Value.Cases[0].Name); + Assert.Equal("1.4L1 + 0.8L3", output.Value.Cases[0].Definition); } } } From 11d54cc29ed798aeb2dc42a2c004077b5714ab5b Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 23 Dec 2024 12:03:41 +0530 Subject: [PATCH 06/15] GSAGH-550: constructor made private --- GsaGH/Helpers/Assembly/ModelAssembly.cs | 2 +- GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs | 4 +++- .../1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs | 10 +++++----- GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index 2f98387ed..7d362a878 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -252,7 +252,7 @@ private void ConvertAndAssembleAnalysisTasks(List analysisTasks // Set Analysis Tasks in model if (analysisTasks != null) { foreach (GsaAnalysisTask task in analysisTasks) { - task.Id = TaskHelper.ImportAnalysisTask(task, ref _model); + TaskHelper.ImportAnalysisTask(task, _model); } } } diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs index 0f8ecce80..aa45d1940 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs @@ -14,7 +14,9 @@ public class GsaAnalysisCase { internal int Id { get; set; } = 0; public string Definition => ApiCase?.Description; public string Name => ApiCase?.Name; - + private GsaAnalysisCase() { + ApiCase = new AnalysisCase(string.Empty, string.Empty); + } public GsaAnalysisCase(string name, string description) { ApiCase = new AnalysisCase(name, description); } diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs index 3cfd369d8..ca2c44cb8 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs @@ -59,10 +59,9 @@ public void AnalysisCasesAreAppendedWhenAnalysisCaseIsAlreadyAttachedToAnotherTa GsaAnalysisTask newTask = CreateTask(); //and assign same analysis case Id newTask.Cases.Add(new GsaAnalysisCase("AnyName", "L1")); - - int newTaskId = TaskHelper.ImportAnalysisTask(newTask, ref _model); + TaskHelper.ImportAnalysisTask(newTask, ref _model); Assert.Equal(2, _model.ApiModel.AnalysisTasks().Keys.Max()); - int newAnalysCaseId = _model.ApiModel.AnalysisTasks()[newTaskId].Cases[0]; + int newAnalysCaseId = _model.ApiModel.AnalysisTasks()[newTask.Id].Cases[0]; Assert.Equal(analysisCaseId + 1, newAnalysCaseId); } @@ -88,8 +87,9 @@ public void AnalysisCasesWillBeEmptyInAbsenceOfLoadCase() { [Fact] public void NullTaskWillNotBeImported() { - int TaskId = TaskHelper.ImportAnalysisTask(new GsaAnalysisTask(), ref _model); - Assert.Equal(-1, TaskId); + var task = new GsaAnalysisTask(); + TaskHelper.ImportAnalysisTask(task, ref _model); + Assert.Equal(0, task.Id); Assert.Empty(_model.ApiModel.AnalysisTasks()); } diff --git a/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs b/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs index 7fd0477b8..3369503e8 100644 --- a/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs +++ b/GsaGHTests/2_GooWrappers/GH_OasysGooTest.cs @@ -57,7 +57,7 @@ public class GhOasysGooTest { [InlineData(typeof(GsaLoadCaseGoo), typeof(GsaLoadCase))] // 4_Analysis - // [InlineData(typeof(GsaAnalysisCaseGoo), typeof(GsaAnalysisCase))] + [InlineData(typeof(GsaAnalysisCaseGoo), typeof(GsaAnalysisCase))] //[InlineData(typeof(GsaAnalysisTaskGoo), typeof(GsaAnalysisTask))] [InlineData(typeof(GsaCombinationCaseGoo), typeof(GsaCombinationCase))] From 46a194d6544902980645a92eca03b789fd5d6422 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 23 Dec 2024 12:05:53 +0530 Subject: [PATCH 07/15] GSAGH-550:missing file added --- GsaGH/Helpers/TaskHelper.cs | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 GsaGH/Helpers/TaskHelper.cs diff --git a/GsaGH/Helpers/TaskHelper.cs b/GsaGH/Helpers/TaskHelper.cs new file mode 100644 index 000000000..2ff091890 --- /dev/null +++ b/GsaGH/Helpers/TaskHelper.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +using GsaAPI; + +using GsaGH.Parameters; + +namespace GsaGH.Helpers { + internal static partial class TaskHelper { + public static int CreateDefaultStaticAnalysisTask(ref GsaModel model) { + int taskId = model.ApiModel.AddAnalysisTask(); + model.ApiModel.CreateDefaultAnalysisCasesForTheTask(taskId); + return taskId; + } + + public static int AddAnalysisTask(ref GsaAnalysisTask task, ref GsaModel model) { + int taskId = model.ApiModel.AddAnalysisTask(task.ApiTask); + model.ApiModel.CreateDefaultAnalysisCasesForTheTask(taskId); + return taskId; + } + + public static void ImportAnalysisTask(GsaAnalysisTask task, ref GsaModel model) { + ReadOnlyDictionary existingTasks = model.ApiModel.AnalysisTasks(); + if (task != null && !existingTasks.Keys.Contains(task.Id)) { + int highestTask = existingTasks.Count(); + var analysisCases = new Dictionary(); + foreach (GsaAnalysisCase analysisCase in task.Cases) { + analysisCases.Add(analysisCase.Id, new AnalysisCase(analysisCase.Name, analysisCase.Definition)); + } + if (task.ApiTask != null) { + if (analysisCases.Count == 0) { + AddAnalysisTask(ref task, ref model); + } else { + model.ApiModel.ImportAnalysisTask(task.ApiTask, new ReadOnlyDictionary(analysisCases)); + task.Id = highestTask + 1; + } + } + } + } + + public static void ImportAnalysisTask(GsaAnalysisTask task, Model model) { + var gsaModel = new GsaModel(model); + ImportAnalysisTask(task, ref gsaModel); + } + } +} From eb2692c7014f1eb75676e088ee05e79e129ec915 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 23 Dec 2024 12:27:07 +0530 Subject: [PATCH 08/15] GSAGH-550:remove ref parameter --- GsaGH/Components/4_Analysis/AnalyseModel.cs | 2 +- GsaGH/Helpers/TaskHelper.cs | 11 +++++------ .../4_Analysis/GsaAnalysisTaskTest.cs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/GsaGH/Components/4_Analysis/AnalyseModel.cs b/GsaGH/Components/4_Analysis/AnalyseModel.cs index 9ee3be477..89d8aeba5 100644 --- a/GsaGH/Components/4_Analysis/AnalyseModel.cs +++ b/GsaGH/Components/4_Analysis/AnalyseModel.cs @@ -222,7 +222,7 @@ protected override void SolveInternal(IGH_DataAccess da) { if (_analysis) { IReadOnlyDictionary gsaTasks = model.ApiModel.AnalysisTasks(); if (gsaTasks.Count < 1) { - int taskId = TaskHelper.CreateDefaultStaticAnalysisTask(ref model); + int taskId = TaskHelper.CreateDefaultStaticAnalysisTask(model); var task = new GsaAnalysisTask(taskId, model.ApiModel); if (task.Cases == null || task.Cases.Count == 0) { this.AddRuntimeWarning( diff --git a/GsaGH/Helpers/TaskHelper.cs b/GsaGH/Helpers/TaskHelper.cs index 2ff091890..ca8d5e5b7 100644 --- a/GsaGH/Helpers/TaskHelper.cs +++ b/GsaGH/Helpers/TaskHelper.cs @@ -9,16 +9,15 @@ namespace GsaGH.Helpers { internal static partial class TaskHelper { - public static int CreateDefaultStaticAnalysisTask(ref GsaModel model) { + public static int CreateDefaultStaticAnalysisTask(GsaModel model) { int taskId = model.ApiModel.AddAnalysisTask(); model.ApiModel.CreateDefaultAnalysisCasesForTheTask(taskId); return taskId; } - public static int AddAnalysisTask(ref GsaAnalysisTask task, ref GsaModel model) { - int taskId = model.ApiModel.AddAnalysisTask(task.ApiTask); - model.ApiModel.CreateDefaultAnalysisCasesForTheTask(taskId); - return taskId; + public static void AddAnalysisTask(GsaAnalysisTask task, GsaModel model) { + task.Id = model.ApiModel.AddAnalysisTask(task.ApiTask); + model.ApiModel.CreateDefaultAnalysisCasesForTheTask(task.Id); } public static void ImportAnalysisTask(GsaAnalysisTask task, ref GsaModel model) { @@ -31,7 +30,7 @@ public static void ImportAnalysisTask(GsaAnalysisTask task, ref GsaModel model) } if (task.ApiTask != null) { if (analysisCases.Count == 0) { - AddAnalysisTask(ref task, ref model); + AddAnalysisTask(task, model); } else { model.ApiModel.ImportAnalysisTask(task.ApiTask, new ReadOnlyDictionary(analysisCases)); task.Id = highestTask + 1; diff --git a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs index ca2c44cb8..74f37bf1f 100644 --- a/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs +++ b/GsaGHTests/1_BaseParameters/4_Analysis/GsaAnalysisTaskTest.cs @@ -67,7 +67,7 @@ public void AnalysisCasesAreAppendedWhenAnalysisCaseIsAlreadyAttachedToAnotherTa [Fact] public void ShouldCreateDefaultTask() { - TaskHelper.CreateDefaultStaticAnalysisTask(ref _model); + TaskHelper.CreateDefaultStaticAnalysisTask( _model); Assert.Single(_model.ApiModel.AnalysisTasks()); } From de2499bec770417da84c99b006c29c8c3e6b68e9 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 23 Dec 2024 13:11:47 +0530 Subject: [PATCH 09/15] GSAGH-550: sonar cloud suggestion --- GsaGH/Helpers/Assembly/ModelAssembly.cs | 2 -- GsaGH/Helpers/TaskHelper.cs | 2 +- GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs | 10 +++++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index 7d362a878..ce4c73c78 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -29,7 +29,6 @@ internal partial class ModelAssembly { private GsaIntDictionary _axes; private GsaGuidIntListDictionary _elements; private GsaIntDictionary _gridLines; - private GsaModel _gsaModel; private GsaGuidDictionary _lists; private ConcurrentDictionary> memberElementRelationship; private GsaGuidDictionary _members; @@ -595,7 +594,6 @@ private void ReportWarningFromAddingGridSurfacesOrList(string mes, string troubl private void SetupModel(GsaModel model, LengthUnit unit) { model ??= new GsaModel(); _model = model.ApiModel; - _gsaModel = model; _unit = unit; _model.UiUnits().LengthLarge = UnitMapping.GetApiUnit(_unit); UiUnits units = _model.UiUnits(); diff --git a/GsaGH/Helpers/TaskHelper.cs b/GsaGH/Helpers/TaskHelper.cs index ca8d5e5b7..9889d1af7 100644 --- a/GsaGH/Helpers/TaskHelper.cs +++ b/GsaGH/Helpers/TaskHelper.cs @@ -23,7 +23,7 @@ public static void AddAnalysisTask(GsaAnalysisTask task, GsaModel model) { public static void ImportAnalysisTask(GsaAnalysisTask task, ref GsaModel model) { ReadOnlyDictionary existingTasks = model.ApiModel.AnalysisTasks(); if (task != null && !existingTasks.Keys.Contains(task.Id)) { - int highestTask = existingTasks.Count(); + int highestTask = existingTasks.Count; var analysisCases = new Dictionary(); foreach (GsaAnalysisCase analysisCase in task.Cases) { analysisCases.Add(analysisCase.Id, new AnalysisCase(analysisCase.Name, analysisCase.Definition)); diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs index a9b770b0a..cd6416dd5 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisTask.cs @@ -7,6 +7,8 @@ using GsaGH.Helpers; +using Rhino.Commands; + namespace GsaGH.Parameters { /// /// An analysis task is a package of work for the solver. Thus we can have a static analysis task, a modal analysis task, etc. Each analysis task has one or more analysis case(s). The distinction is that the cases corresponds to result sets and define items such as loading (in the static case) while the task describes what the solver has to do. @@ -33,11 +35,9 @@ internal GsaAnalysisTask(AnalysisTask task, Model model) { } private void CreateCases(Model model) { ReadOnlyDictionary analysisCases = model.AnalysisCases(); - foreach (int caseId in ApiTask.Cases) { - if (analysisCases.ContainsKey(caseId)) { - AnalysisCase analysisCase = model.AnalysisCases()[caseId]; - Cases.Add(new GsaAnalysisCase(caseId, analysisCase.Name, analysisCase.Description)); - } + foreach (int caseId in ApiTask.Cases.Where(x => analysisCases.ContainsKey(x))) { + AnalysisCase analysisCase = model.AnalysisCases()[caseId]; + Cases.Add(new GsaAnalysisCase(caseId, analysisCase.Name, analysisCase.Description)); } } public override string ToString() { From 6d00bbc68e15d26aafec266d5b38b52fdf138479 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 23 Dec 2024 14:58:05 +0530 Subject: [PATCH 10/15] GSAGH-550: updated integration test as load case and analysis case are two different things --- .../4_Analysis/AnalysisTaskAndCaseTest.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/IntegrationTests/2_Parameters/4_Analysis/AnalysisTaskAndCaseTest.cs b/IntegrationTests/2_Parameters/4_Analysis/AnalysisTaskAndCaseTest.cs index bb846e0f0..fb7f8b6f1 100644 --- a/IntegrationTests/2_Parameters/4_Analysis/AnalysisTaskAndCaseTest.cs +++ b/IntegrationTests/2_Parameters/4_Analysis/AnalysisTaskAndCaseTest.cs @@ -61,13 +61,9 @@ public void AnalysisCaseNameTest() { .Name.Replace("Test", string.Empty)); var output0 = (GH_String)param.VolatileData.get_Branch(0)[0]; var output1 = (GH_String)param.VolatileData.get_Branch(0)[1]; - var output2 = (GH_String)param.VolatileData.get_Branch(0)[2]; - var output3 = (GH_String)param.VolatileData.get_Branch(0)[3]; Assert.Equal("DL", output0.Value); Assert.Equal("LL", output1.Value); - Assert.Equal("DL", output2.Value); - Assert.Equal("LL", output3.Value); } [Fact] @@ -76,13 +72,10 @@ public void AnalysisCaseDescriptionTest() { .Name.Replace("Test", string.Empty)); var output0 = (GH_String)param.VolatileData.get_Branch(0)[0]; var output1 = (GH_String)param.VolatileData.get_Branch(0)[1]; - var output2 = (GH_String)param.VolatileData.get_Branch(0)[2]; - var output3 = (GH_String)param.VolatileData.get_Branch(0)[3]; Assert.Equal("L1", output0.Value); Assert.Equal("L2", output1.Value); - Assert.Equal("L1", output2.Value); - Assert.Equal("L2", output3.Value); + } [Fact] @@ -91,13 +84,9 @@ public void AnalysisCaseIdTest() { .Name.Replace("Test", string.Empty)); var output0 = (GH_Integer)param.VolatileData.get_Branch(0)[0]; var output1 = (GH_Integer)param.VolatileData.get_Branch(0)[1]; - var output2 = (GH_Integer)param.VolatileData.get_Branch(0)[2]; - var output3 = (GH_Integer)param.VolatileData.get_Branch(0)[3]; Assert.Equal(1, output0.Value); Assert.Equal(2, output1.Value); - Assert.Equal(1, output2.Value); - Assert.Equal(2, output3.Value); } [Fact] From 64932b51d2f8d054c55cf647ff1275be0193bc75 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Tue, 24 Dec 2024 13:03:29 +0530 Subject: [PATCH 11/15] GSAGH-550: can not be null --- GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs index aa45d1940..5286e6435 100644 --- a/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs +++ b/GsaGH/Parameters/4_Analysis/GsaAnalysisCase.cs @@ -12,8 +12,8 @@ namespace GsaGH.Parameters { public class GsaAnalysisCase { private AnalysisCase ApiCase { get; set; } internal int Id { get; set; } = 0; - public string Definition => ApiCase?.Description; - public string Name => ApiCase?.Name; + public string Definition => ApiCase.Description; + public string Name => ApiCase.Name; private GsaAnalysisCase() { ApiCase = new AnalysisCase(string.Empty, string.Empty); } From 4e8098a484f016ca2add97c3eea4603ad91d1a7c Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 30 Dec 2024 17:40:28 +0530 Subject: [PATCH 12/15] GSAGH-550: using single assertion --- .../1_BaseParameters/0_Model/GsaModelTest.cs | 23 ++++--------------- .../TestHelpers/DuplicatesAreEqualTest.cs | 12 ++++++++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs index 06896ee78..0d517267e 100644 --- a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs +++ b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.IO; using GsaAPI; @@ -16,7 +15,6 @@ using OasysUnits; using Rhino.Geometry; -using Rhino.Runtime; using Xunit; @@ -142,30 +140,19 @@ public void AnalysisTaskAndCasesCanBeImportedFromSeedModel() { seedModel.ApiModel.Open(GsaFile.SteelDesignComplex); List seedTasks = seedModel.GetAnalysisTasksAndCombinations().Item1; var analysis = new GsaAnalysis(); - foreach (GsaAnalysisTaskGoo task in seedModel.GetAnalysisTasksAndCombinations().Item1) { + foreach (GsaAnalysisTaskGoo task in seedTasks) { 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 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.Name, seedCase.Name); - Assert.Equal(importedCase.Definition, seedCase.Definition); - } - } + Assert.True(Duplicates.AreEqual(seedTasks, importedTasks)); + } } } diff --git a/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs b/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs index 9e33eace4..3df20f080 100644 --- a/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs +++ b/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs @@ -7,7 +7,15 @@ using Xunit; namespace GsaGHTests.Helpers { - public class Duplicates { + public static class Duplicates { + + public static bool AreEqual(ICollection objA, ICollection objB) { + Assert.Equal(objA.Count, objB.Count); + for (int i = 0; i < objA.Count; i++) { + if (!AreEqual(objA.ElementAt(i), objB.ElementAt(i))) { return false; } + } + return true; + } public static bool AreEqual(object objA, object objB, List excluded = null) { Assert.Equal(objA.ToString(), objB.ToString()); @@ -123,7 +131,7 @@ PropertyInfo[] propertyInfoB } else { AreEqual(objPropertyValueA, objPropertyValueB, excluded); } - } catch (TargetParameterCountException) { } + } catch (TargetParameterCountException) { return false; } } return true; From 16a5ca4f8449022ac1f141bb6b032d5c9c142ad5 Mon Sep 17 00:00:00 2001 From: SandeepArup <61278421+SandeepArup@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:48:19 +0530 Subject: [PATCH 13/15] Update GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs Co-authored-by: Stamatios Psarras --- GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs index 0d517267e..3fa838682 100644 --- a/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs +++ b/GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs @@ -132,6 +132,16 @@ public void TestModelLengthUnit() { Assert.Equal(LengthUnit.Foot, UnitMapping.GetUnit(m.ApiModel.UiUnits().LengthLarge)); } + [Fact] + public void ShouldNotHaveAnyTasks() { + GsaAnalysis gsaAnalysis = null; + var assembly = new ModelAssembly(null, null, null, null, null, null, gsaAnalysis, LengthUnit.Meter, Length.Zero, + false, null); + var model = new GsaModel(assembly.GetModel()); + List importedTasks = model.GetAnalysisTasksAndCombinations().Item1; + Assert.Empty(importedTasks); + Assert.Empty(importedTasks); + } [Fact] public void AnalysisTaskAndCasesCanBeImportedFromSeedModel() { From 2ef2ec2541e9fe96734e160674481340a12c49ef Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 30 Dec 2024 19:06:40 +0530 Subject: [PATCH 14/15] GSAGH-550: exclude guid in comparing object --- GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs b/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs index 3df20f080..0cc39f677 100644 --- a/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs +++ b/GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs @@ -18,6 +18,9 @@ public static bool AreEqual(ICollection objA, ICollection objB) { } public static bool AreEqual(object objA, object objB, List excluded = null) { + if (excluded == null) { + excluded = new List() { "Guid" }; + } Assert.Equal(objA.ToString(), objB.ToString()); Type typeA = objA.GetType(); @@ -131,7 +134,9 @@ PropertyInfo[] propertyInfoB } else { AreEqual(objPropertyValueA, objPropertyValueB, excluded); } - } catch (TargetParameterCountException) { return false; } + } catch (TargetParameterCountException) { + return false; + } } return true; From 7789e2beb2e2f3c88ae77dc2aedfbbdfc9bd6d8f Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Tue, 7 Jan 2025 12:46:49 +0530 Subject: [PATCH 15/15] GSAGH-550: fix failing test in latest nightly build --- GsaGH/Components/4_Analysis/AnalyseModel.cs | 1 + .../2_Parameters/2_Geometry/Section3dPreviewTests.cs | 2 +- IntegrationTests/3_Components/FootfallResultsTests.cs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/GsaGH/Components/4_Analysis/AnalyseModel.cs b/GsaGH/Components/4_Analysis/AnalyseModel.cs index 89d8aeba5..46f3d3fbc 100644 --- a/GsaGH/Components/4_Analysis/AnalyseModel.cs +++ b/GsaGH/Components/4_Analysis/AnalyseModel.cs @@ -118,6 +118,7 @@ protected override void BeforeSolveInstance() { // add report output to old components if (Params.Output.Count < 5) { + Params.RegisterOutputParam(new Param_String()); Params.Output[1].Name = "Errors"; Params.Output[1].NickName = "E"; Params.Output[1].Description = "Analysis Task Errors"; diff --git a/IntegrationTests/2_Parameters/2_Geometry/Section3dPreviewTests.cs b/IntegrationTests/2_Parameters/2_Geometry/Section3dPreviewTests.cs index b70aae5f0..3b77ecbae 100644 --- a/IntegrationTests/2_Parameters/2_Geometry/Section3dPreviewTests.cs +++ b/IntegrationTests/2_Parameters/2_Geometry/Section3dPreviewTests.cs @@ -24,7 +24,7 @@ public void DeformedMeshTest() { Mesh mesh = valOut.Value; Assert.NotNull(mesh); Assert.Equal(3452, mesh.Vertices.Count); - Assert.Equal(4722, mesh.Faces.Count); + Assert.Equal(4719, mesh.Faces.Count); } [Fact] diff --git a/IntegrationTests/3_Components/FootfallResultsTests.cs b/IntegrationTests/3_Components/FootfallResultsTests.cs index 784f2a82d..919f4f804 100644 --- a/IntegrationTests/3_Components/FootfallResultsTests.cs +++ b/IntegrationTests/3_Components/FootfallResultsTests.cs @@ -15,8 +15,8 @@ public class FootfallResultsTests { [Theory] [InlineData("MaxLegend2d", (double)9)] [InlineData("MaxLegend1d", (double)9)] - [InlineData("Resonant", 9.517186)] - [InlineData("Transient", 4.413146)] + [InlineData("Resonant", 9.515605)] + [InlineData("Transient", 4.4132066)] [InlineData("MaxLegendNode", (double)10)] public void Test(string groupIdentifier, object expected) { IGH_Param param = Helper.FindParameter(Document, groupIdentifier);