-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from MagmaWorks/bugfix/perimter-from-perimeter
Handle IPerimeter from Perimeter and Perimeter tests
- Loading branch information
Showing
3 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using MagmaWorks.Geometry; | ||
using MagmaWorks.Taxonomy.Profiles; | ||
using MagmaWorks.Taxonomy.Serialization.Profiles.Extensions; | ||
using OasysUnits; | ||
using OasysUnits.Units; | ||
|
||
namespace ProfileTests | ||
{ | ||
public class PerimeterTests | ||
{ | ||
[Fact] | ||
public void CreateProfileTest() | ||
{ | ||
// Assemble | ||
LengthUnit unit = LengthUnit.Centimeter; | ||
var solidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(-50, unit)}, | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(-50, unit)}, | ||
}); | ||
var voidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(-15, unit)}, | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(-15, unit)}, | ||
}); | ||
|
||
// Act | ||
IPerimeter profile = new Perimeter(solidEdge, new List<ILocalPolygon2d>() { voidEdge }); | ||
|
||
// Assert | ||
Assert.Single(profile.VoidEdges); | ||
Assert.Equal(4, profile.OuterEdge.Points.Count); | ||
Assert.Equal(4, profile.VoidEdges[0].Points.Count); | ||
} | ||
|
||
[Fact] | ||
public void InterfaceSurvivesRoundtripDeserializationTest() | ||
{ | ||
// Assemble | ||
LengthUnit unit = LengthUnit.Centimeter; | ||
var solidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(-50, unit)}, | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(-50, unit)}, | ||
}); | ||
var voidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(-15, unit)}, | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(-15, unit)}, | ||
}); | ||
|
||
// Act | ||
IPerimeter prfl = new Perimeter(solidEdge, new List<ILocalPolygon2d>() { voidEdge }); | ||
string json = prfl.ToJson(); | ||
IPerimeter prflDeserialized = json.FromJson<IPerimeter>(); | ||
|
||
// Assert | ||
Assert.Single(prflDeserialized.VoidEdges); | ||
Assert.Equal(4, prflDeserialized.OuterEdge.Points.Count); | ||
Assert.Equal(4, prflDeserialized.VoidEdges[0].Points.Count); | ||
Assert.Equivalent(prfl, prflDeserialized); | ||
} | ||
|
||
[Fact] | ||
public void ConcreteImplementationSurvivesRoundtripDeserializationTest() | ||
{ | ||
// Assemble | ||
LengthUnit unit = LengthUnit.Centimeter; | ||
var solidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(-50, unit)}, | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(-50, unit)}, | ||
}); | ||
var voidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(-15, unit)}, | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(-15, unit)}, | ||
}); | ||
|
||
// Act | ||
IPerimeter prfl = new Perimeter(solidEdge, new List<ILocalPolygon2d>() { voidEdge }); | ||
string json = prfl.ToJson(); | ||
IPerimeter prflDeserialized = json.FromJson<Perimeter>(); | ||
|
||
// Assert | ||
Assert.Single(prflDeserialized.VoidEdges); | ||
Assert.Equal(4, prflDeserialized.OuterEdge.Points.Count); | ||
Assert.Equal(4, prflDeserialized.VoidEdges[0].Points.Count); | ||
Assert.Equivalent(prfl, prflDeserialized); | ||
} | ||
|
||
[Fact] | ||
public void GetPerimeterTest() | ||
{ | ||
// Assemble | ||
LengthUnit unit = LengthUnit.Centimeter; | ||
var solidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(50, unit)}, | ||
new LocalPoint2d() { Y = new Length(-25, unit), Z = new Length(-50, unit)}, | ||
new LocalPoint2d() { Y = new Length(25, unit), Z = new Length(-50, unit)}, | ||
}); | ||
var voidEdge = new LocalPolygon2d(new List<ILocalPoint2d>() | ||
{ | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(15, unit)}, | ||
new LocalPoint2d() { Y = new Length(-10, unit), Z = new Length(-15, unit)}, | ||
new LocalPoint2d() { Y = new Length(10, unit), Z = new Length(-15, unit)}, | ||
}); | ||
|
||
// Act | ||
IPerimeter prfl = new Perimeter(solidEdge, new List<ILocalPolygon2d>() { voidEdge }); | ||
IPerimeter perimeter = new Perimeter(prfl); | ||
|
||
// Assert | ||
Assert.Single(perimeter.VoidEdges); | ||
Assert.Equal(4, perimeter.OuterEdge.Points.Count); | ||
Assert.Equal(4, perimeter.VoidEdges[0].Points.Count); | ||
Assert.Equivalent(prfl, perimeter); | ||
} | ||
} | ||
} |