From 4e8098a484f016ca2add97c3eea4603ad91d1a7c Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Mon, 30 Dec 2024 17:40:28 +0530 Subject: [PATCH] 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;