Skip to content

Commit

Permalink
GSAGH-550: using single assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
SandeepArup committed Dec 30, 2024
1 parent 64932b5 commit 4e8098a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
23 changes: 5 additions & 18 deletions GsaGHTests/1_BaseParameters/0_Model/GsaModelTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;

using GsaAPI;
Expand All @@ -16,7 +15,6 @@
using OasysUnits;

using Rhino.Geometry;
using Rhino.Runtime;

using Xunit;

Expand Down Expand Up @@ -142,30 +140,19 @@ public void AnalysisTaskAndCasesCanBeImportedFromSeedModel() {
seedModel.ApiModel.Open(GsaFile.SteelDesignComplex);
List<GsaAnalysisTaskGoo> 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<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.Name, seedCase.Name);
Assert.Equal(importedCase.Definition, seedCase.Definition);
}
}
Assert.True(Duplicates.AreEqual(seedTasks, importedTasks));

}
}
}
12 changes: 10 additions & 2 deletions GsaGHTests/TestHelpers/DuplicatesAreEqualTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
using Xunit;

namespace GsaGHTests.Helpers {
public class Duplicates {
public static class Duplicates {

public static bool AreEqual<T>(ICollection<T> objA, ICollection<T> 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<string> excluded = null) {
Assert.Equal(objA.ToString(), objB.ToString());
Expand Down Expand Up @@ -123,7 +131,7 @@ PropertyInfo[] propertyInfoB
} else {
AreEqual(objPropertyValueA, objPropertyValueB, excluded);
}
} catch (TargetParameterCountException) { }
} catch (TargetParameterCountException) { return false; }
}

return true;
Expand Down

0 comments on commit 4e8098a

Please sign in to comment.