diff --git a/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj b/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj
index bbd7d8c..566ba5d 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj
+++ b/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj
@@ -56,6 +56,7 @@
+
diff --git a/OSCADSharp/OSCADSharp.UnitTests/UnionTests.cs b/OSCADSharp/OSCADSharp.UnitTests/UnionTests.cs
new file mode 100644
index 0000000..487d0c7
--- /dev/null
+++ b/OSCADSharp/OSCADSharp.UnitTests/UnionTests.cs
@@ -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("));
+ }
+ }
+}
diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs
index f7ddbaa..fa32235 100644
--- a/OSCADSharp/OSCADSharp/OSCADObject.cs
+++ b/OSCADSharp/OSCADSharp/OSCADObject.cs
@@ -233,7 +233,9 @@ namespace OSCADSharp
///
public IEnumerable Children()
{
- Stack toTraverse = new Stack(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 toTraverse = new Stack(this.children.Reverse());
List allChildren = new List();
OSCADObject child = null;