mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-27 12:58:27 +00:00
+ Added UnionTests
+ Fixed an issue where the children of Union as per Children() appeared in the reverse of the expected order
This commit is contained in:
parent
ae3f9e4d2f
commit
750937a25e
@ -56,6 +56,7 @@
|
|||||||
<Compile Include="OSCADObjectTests.cs" />
|
<Compile Include="OSCADObjectTests.cs" />
|
||||||
<Compile Include="SphereTests.cs" />
|
<Compile Include="SphereTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="UnionTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OSCADSharp\OSCADSharp.csproj">
|
<ProjectReference Include="..\OSCADSharp\OSCADSharp.csproj">
|
||||||
|
|||||||
52
OSCADSharp/OSCADSharp.UnitTests/UnionTests.cs
Normal file
52
OSCADSharp/OSCADSharp.UnitTests/UnionTests.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using OSCADSharp.Solids;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.UnitTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class UnionTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void Union_AffectedObjectsAreChildren()
|
||||||
|
{
|
||||||
|
var union = new Cube().Union(new Cylinder());
|
||||||
|
var children = union.Children();
|
||||||
|
|
||||||
|
Assert.IsTrue(children.ElementAt(0).GetType() == typeof(Cube));
|
||||||
|
Assert.IsTrue(children.ElementAt(1).GetType() == typeof(Cylinder));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Union_AffectedObjectsAreInOutputScript()
|
||||||
|
{
|
||||||
|
var union = new Cube().Union(new Cylinder());
|
||||||
|
string script = union.ToString();
|
||||||
|
|
||||||
|
Assert.IsTrue(script.Contains("cube("));
|
||||||
|
Assert.IsTrue(script.Contains("cylinder("));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Union_FirstStatementInOutputScriptIsUnionMethodCall()
|
||||||
|
{
|
||||||
|
var union = new Cube().Union(new Cylinder());
|
||||||
|
string script = union.ToString();
|
||||||
|
|
||||||
|
Assert.IsTrue(script.StartsWith("union()"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Union_FirstElementAppearsFirstInOutputScript()
|
||||||
|
{
|
||||||
|
var union = new Cube().Union(new Cylinder());
|
||||||
|
string script = union.ToString();
|
||||||
|
|
||||||
|
Assert.IsTrue(script.IndexOf("cube(") < script.IndexOf("cylinder("));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -233,7 +233,9 @@ namespace OSCADSharp
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<OSCADObject> Children()
|
public IEnumerable<OSCADObject> Children()
|
||||||
{
|
{
|
||||||
Stack<OSCADObject> toTraverse = new Stack<OSCADObject>(this.children);
|
// Initial children are reversed here because for objects with multiple children (such as boolean operations)
|
||||||
|
// the natural collection order would yield opposite the expected order in a stack (first child would be the last popped)
|
||||||
|
Stack<OSCADObject> toTraverse = new Stack<OSCADObject>(this.children.Reverse<OSCADObject>());
|
||||||
List<OSCADObject> allChildren = new List<OSCADObject>();
|
List<OSCADObject> allChildren = new List<OSCADObject>();
|
||||||
OSCADObject child = null;
|
OSCADObject child = null;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user