Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdSecGH-63 Fix unflatten Test #98

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 24 additions & 29 deletions AdSecGHTests/Parameters/AdSecSectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,59 @@
namespace AdSecGHTests.Parameters {
[Collection("GrasshopperFixture collection")]
public class AdSecSectionTests {
[Fact(Skip = "Not Implemented Yet")]
[Fact]
public void SerialiseUnflattenedSectionTest() {
ISection section = CreateSection();
var section = CreateSection();

IDesignCode designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013;
var designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013;
var adSec = IAdSec.Create(designCode);
ISection flattened = adSec.Flatten(section);
var flattened = adSec.Flatten(section);

string fileName = Path.GetTempPath() + "AdSecSectionTest.ads";
string fileName = Path.GetTempPath() + "AdSecSectionTest-Unflattened.ads";
File.WriteAllText(fileName, CreateJson(designCode, section));

string json = File.ReadAllText(fileName);
ParsedResult jsonParser = JsonParser.Deserialize(json);
ISection actualSection = jsonParser.Sections[0];
var jsonParser = JsonParser.Deserialize(json);
var actualSection = jsonParser.Sections[0];

var expectedProfile = (IPerimeterProfile)flattened.Profile;
var actualProfile = (IPerimeterProfile)actualSection.Profile;

TestSection(flattened, actualSection);
TestSection(flattened, actualSection, true);
}

[Fact]
public void SerialiaseFlattenedSectionTest() {
ISection section = CreateSection();
var section = CreateSection();

IDesignCode designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013;
var designCode = EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013;
var adSec = IAdSec.Create(designCode);
ISection flattened = adSec.Flatten(section);
var flattened = adSec.Flatten(section);

string fileName = Path.GetTempPath() + "AdSecSectionTest.ads";
File.WriteAllText(fileName, CreateJson(designCode, flattened));

string json = File.ReadAllText(fileName);
ParsedResult jsonParser = JsonParser.Deserialize(json);
ISection actualSection = jsonParser.Sections[0];

var expectedProfile = (IPerimeterProfile)flattened.Profile;
var actualProfile = (IPerimeterProfile)actualSection.Profile;
var jsonParser = JsonParser.Deserialize(json);
var actualSection = jsonParser.Sections[0];

TestSection(flattened, actualSection);
}

private void TestSection(ISection expected, ISection actual) {
private static void TestSection(ISection expected, ISection actual, bool unflattened = false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put this comparison at the core GSA.GH project withi this signature

public class SectionHelper
{
    public static bool Equal(ISection sectionA, ISection sectionB, bool unflattened){...}
}

then this method can simply call the previous one

{
    Assert.True(SectionHelper.Equal(expected, actual, unflattened))
}

var expectedProfile = (IPerimeterProfile)expected.Profile;
var actualProfile = (IPerimeterProfile)actual.Profile;

for (int i = 0; i < expectedProfile.SolidPolygon.Points.Count; i++) {
IPoint expectedPoint = expectedProfile.SolidPolygon.Points[i];
IPoint actualPoint = actualProfile.SolidPolygon.Points[i];
var expectedPoint = expectedProfile.SolidPolygon.Points[i];
var actualPoint = actualProfile.SolidPolygon.Points[i];

Assert.Equal(expectedPoint.Y.Value, actualPoint.Y.Value, 4);
Assert.Equal(expectedPoint.Z.Value, actualPoint.Z.Value, 4);
}

Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).Positions[0].Y.Value, ((ISingleBars)actual.ReinforcementGroups[0]).Positions[0].Y.Value, 4);
Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).Positions[0].Z.Value, ((ISingleBars)actual.ReinforcementGroups[0]).Positions[0].Z.Value, 4);
Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).BarBundle.CountPerBundle, ((ISingleBars)actual.ReinforcementGroups[0]).BarBundle.CountPerBundle);
Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).BarBundle.Diameter, ((ISingleBars)actual.ReinforcementGroups[0]).BarBundle.Diameter);
if (!unflattened) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SandeepArup is there a method for testing if a Section if unflattened or flatten? I don't like that we dictate if that is the case. There must be an internal flag we can reuse?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RaviKumarGubbala @vilayatk is there any flag which tell section is unflattened or flatten?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such kind of check shouldn't be there. Is it added becuase test are failing? I think the test fails becuase CountPerBundle cant be checked before after flatten. If there are three bars per bundle, it might be geting converted to three single bars. After confirming the behaviour we could update/delete the check related CountPerBundle. @SandeepArup

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @RaviKumarGubbala. However, "It might be" OR always converting bar in bundle to single bars?

These tests are json sterilization and deserialization test i.e. b/w flatten and original section and vice-versa and have only one bar in bundle. So, test should not fail in either case. @DominikaLos lets discuss this tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psarras I had some discussion with @RaviKumarGubbala and have feeling that after flattening section, profile will get changed(although section geometry will remain same) and so center of gravity and rebar position will be changed relative to new Origin/CG position and there is no guarantee that we can match the position with original section.

And second things, why these tests? Should we write test for third party library? If consuming Revit API or Grasshopper API, should we write test for their functionalities? If we are finding some issue in AdSec API then It should be reported to AdSec team for resolution.

So, in my opinion, these test should not be here.

Copy link
Collaborator

@psarras psarras Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SandeepArup Hey! I agree we shouldn't be testing GSA.API here. I will need to look into more detail to understand if we simply remove them, however, I have the feeling they are also testing some secondary functionality, of which we need a test. So perhaps we morph this problem to something that helps us.

Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).Positions[0].Y.Value, ((ISingleBars)actual.ReinforcementGroups[0]).Positions[0].Y.Value, 4);
Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).Positions[0].Z.Value, ((ISingleBars)actual.ReinforcementGroups[0]).Positions[0].Z.Value, 4);
Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).BarBundle.CountPerBundle, ((ISingleBars)actual.ReinforcementGroups[0]).BarBundle.CountPerBundle);
Assert.Equal(((ISingleBars)expected.ReinforcementGroups[0]).BarBundle.Diameter, ((ISingleBars)actual.ReinforcementGroups[0]).BarBundle.Diameter);
}

Assert.Equal(expectedProfile.ElasticModulus().Y.Value, actualProfile.ElasticModulus().Y.Value, 10);
Assert.Equal(expectedProfile.ElasticModulus().Z.Value, actualProfile.ElasticModulus().Z.Value, 10);
Expand All @@ -95,7 +90,7 @@ private static string CreateJson(IDesignCode designCode, ISection section) {

private static ISection CreateSection() {
IMaterial material = Oasys.AdSec.StandardMaterials.Concrete.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.C40_50;
IReinforcement rebarMaterial = Oasys.AdSec.StandardMaterials.Reinforcement.Steel.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.S500B;
var rebarMaterial = Oasys.AdSec.StandardMaterials.Reinforcement.Steel.EN1992.Part1_1.Edition_2004.NationalAnnex.DE.Edition_2013.S500B;

var points = new List<IPoint2d>() {
new Point2d(new Length(3.1464410643837, LengthUnit.Meter), new Length(2.9552083887352, LengthUnit.Meter)),
Expand Down Expand Up @@ -134,7 +129,7 @@ private static ISection CreateSection() {

var polygon = new Polygon(points);
var profile = new Oasys.Taxonomy.Profiles.PerimeterProfile(polygon, new List<Oasys.Taxonomy.Geometry.IPolygon>());
IPerimeterProfile adsecProfile = AdSecProfiles.CreatePerimeterProfile(profile);
var adsecProfile = AdSecProfiles.CreatePerimeterProfile(profile);
var section = ISection.Create(adsecProfile, material);

var bars = ISingleBars.Create(IBarBundle.Create(rebarMaterial, new Length(25, LengthUnit.Millimeter)));
Expand Down
Loading