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

Add tests #47

Closed
wants to merge 13 commits into from
3 changes: 2 additions & 1 deletion LayoutFunctions/ClassroomLayout/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ obj/
*.glb
output.json
input.json
.vs/**/*.*
.vs/**/*.*
test/Generated/
91 changes: 91 additions & 0 deletions LayoutFunctions/ClassroomLayout/test/ClassroomLayoutTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Elements;
using Xunit;
using System.IO;
using System.Collections.Generic;
using Elements.Serialization.glTF;
using Newtonsoft.Json;
using Elements.Components;
using System.Linq;
using LayoutFunctionCommon;

namespace ClassroomLayout.Tests
{
public class ClassroomLayoutTests
{
private const string INPUT = "../../../_input/";
private const string OUTPUT = "../../../_output/";
private string[] orderedKeys = new[] { "Classroom-A", "Classroom-B", "Classroom-C" };

[Fact]
public void ClassroomConfigurations()
{
// Test with one room for each configuration to check that every piece of expected content exists in a room of a matching size
var testName = "Configurations";
var configs = LayoutStrategies.GetConfigurations("ClassroomConfigurations.json");

// Get the result of ClassroomLayout.Execute()
var (output, spacePlanningModel) = ClassroomLayoutTest(testName);
var elements = output.Model.AllElementsOfType<ElementInstance>();

// Get the rooms created according to the orderedKeys order
var boundaries = spacePlanningModel.AllElementsOfType<SpaceBoundary>().Where(z => z.Name == "Classroom").OrderBy(b => b.Bounds.Center().Y).ToList();

// Check each configuration separately
for (int i = 0; i < orderedKeys.Count(); i++)
{
// Confirm that the size of the room covers the size of the corresponding configuration
var boundary = boundaries[i];
var config = configs.FirstOrDefault(c => c.Key == orderedKeys[i]).Value;
Assert.True(config.Depth < boundary.Bounds.XSize);

// Look for all the furniture placed within the room
var offsetedBox = boundary.Bounds.Offset(0.1);
var boundaryElements = elements.Where(e => offsetedBox.Contains(e.Transform.Origin)).ToList();

// Check that the room has all furniture that are in the appropriate configuration
foreach (var contentItem in config.ContentItems)
{
var boundaryElement = boundaryElements.FirstOrDefault(be => be.Name == contentItem.Name || be.Name == contentItem.Url);
Assert.NotNull(boundaryElement);
boundaryElements.Remove(boundaryElement);
}
}

// room with 9 desks
var roomWithDesks = boundaries.Last();
var offsetedBoxWithDesks = roomWithDesks.Bounds.Offset(0.1);
var boundaryElementsWithDesks = elements.Where(e => offsetedBoxWithDesks.Contains(e.Transform.Origin)).ToList();
Assert.Equal(9, boundaryElementsWithDesks.Where(be => be.Name == "Desk").Count());
}

private (ClassroomLayoutOutputs output, Model spacePlanningModel) ClassroomLayoutTest(string testName)
{
var spacePlanningModel = Model.FromJson(System.IO.File.ReadAllText($"{INPUT}/{testName}/Space Planning Zones.json"));
var levelsModel = Model.FromJson(System.IO.File.ReadAllText($"{INPUT}/{testName}/Levels.json"));
var circulationModel = Model.FromJson(System.IO.File.ReadAllText($"{INPUT}/{testName}/Circulation.json"));
var input = GetInput(testName);
var output = ClassroomLayout.Execute(
new Dictionary<string, Model>
{
{"Space Planning Zones", spacePlanningModel},
{"Levels", levelsModel},
{"Circulation", circulationModel},
}, input);

System.IO.File.WriteAllText($"{OUTPUT}/{testName}/ClassroomLayout.json", output.Model.ToJson());
output.Model.AddElements(spacePlanningModel.Elements.Values);
output.Model.AddElements(levelsModel.Elements.Values);
output.Model.AddElements(circulationModel.Elements.Values);
output.Model.ToGlTF($"{OUTPUT}/{testName}/ClassroomLayout.glb");
output.Model.ToGlTF($"{OUTPUT}/{testName}/ClassroomLayout.gltf", false);

return (output, spacePlanningModel);
}

private ClassroomLayoutInputs GetInput(string testName)
{
var json = File.ReadAllText($"{INPUT}/{testName}/inputs.json");
return Newtonsoft.Json.JsonConvert.DeserializeObject<ClassroomLayoutInputs>(json);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Elements":{"5b6ec190-bf9e-47a3-b8e9-718883352cfd":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":9.25164,"Y":30.0,"Z":0.0},{"X":7.75164,"Y":30.0,"Z":0.0},{"X":7.64952,"Y":0.0,"Z":0.0},{"X":9.14953,"Y":0.0,"Z":0.0}]},"Voids":[],"Id":"5b6ec190-bf9e-47a3-b8e9-718883352cfd","Name":"Corridor"},"9f05bd39-2950-40cc-a11c-bbaafc475de5":{"discriminator":"Elements.Material","Color":{"Red":0.996,"Green":0.965,"Blue":0.863,"Alpha":1.0},"SpecularFactor":0.1,"GlossinessFactor":0.1,"Unlit":false,"DoubleSided":true,"RepeatTexture":true,"InterpolateTexture":true,"EmissiveFactor":1.0,"Draw In Front":false,"EdgeDisplaySettings":null,"Id":"9f05bd39-2950-40cc-a11c-bbaafc475de5","Name":"Circulation"},"46f7228d-f3a9-4bdf-8da4-7f8054d2cf20":{"discriminator":"Elements.CirculationSegment","Geometry":{"discriminator":"Circulation.ThickenedPolyline","polyline":{"discriminator":"Elements.Geometry.Polyline","Vertices":[{"X":9.251641111102469,"Y":29.999,"Z":-5.0},{"X":9.149529177258614,"Y":0.001,"Z":-5.0}]},"width":1.5,"flip":false,"leftWidth":0.0,"rightWidth":1.5},"Original Geometry":{"discriminator":"Elements.Geometry.Polyline","Vertices":[{"X":5.75,"Y":22.0,"Z":0.0},{"X":5.75,"Y":8.0,"Z":0.0}]},"Level":"e7f8302c-cdc5-4bb2-94e0-5d7934c60b93","Thickness":0.01,"Profile":"5b6ec190-bf9e-47a3-b8e9-718883352cfd","Openings":[],"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,-5.0]}},"Material":"9f05bd39-2950-40cc-a11c-bbaafc475de5","Representation":{"SolidOperations":[{"discriminator":"Elements.Geometry.Solids.Extrude","Profile":"5b6ec190-bf9e-47a3-b8e9-718883352cfd","Height":0.01,"Direction":{"X":0.0,"Y":0.0,"Z":1.0},"Reverse Winding":false,"LocalTransform":null,"IsVoid":false}]},"IsElementDefinition":false,"Id":"46f7228d-f3a9-4bdf-8da4-7f8054d2cf20","Name":null,"associatedIdentities":{"Corridors":[{"id":"76ae45e6-ec8e-444b-a379-04b0e2ebf177","identity":{"Original Geometry":{"discriminator":"Elements.Geometry.Polyline","Vertices":[{"X":5.75,"Y":22.0,"Z":0.0},{"X":5.75,"Y":8.0,"Z":0.0}]}}}]}},"d0cf3285-cb76-42e1-ba33-8db203007dae":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":9.25164,"Y":30.0,"Z":0.0},{"X":7.75164,"Y":30.0,"Z":0.0},{"X":7.64952,"Y":0.0,"Z":0.0},{"X":9.14953,"Y":0.0,"Z":0.0}]},"Voids":[],"Id":"d0cf3285-cb76-42e1-ba33-8db203007dae","Name":"Corridor"},"20472b77-5b83-4096-b6a3-52dcbb7cf80e":{"discriminator":"Elements.CirculationSegment","Geometry":{"discriminator":"Circulation.ThickenedPolyline","polyline":{"discriminator":"Elements.Geometry.Polyline","Vertices":[{"X":9.251641111102469,"Y":29.999,"Z":-5.0},{"X":9.149529177258614,"Y":0.001,"Z":-5.0}]},"width":1.5,"flip":false,"leftWidth":0.0,"rightWidth":1.5},"Original Geometry":{"discriminator":"Elements.Geometry.Polyline","Vertices":[{"X":5.75,"Y":22.0,"Z":0.0},{"X":5.75,"Y":8.0,"Z":0.0}]},"Level":"ff6eaf49-0e35-490d-8e74-d42766c5f3f2","Thickness":0.01,"Profile":"d0cf3285-cb76-42e1-ba33-8db203007dae","Openings":[],"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Material":"9f05bd39-2950-40cc-a11c-bbaafc475de5","Representation":{"SolidOperations":[{"discriminator":"Elements.Geometry.Solids.Extrude","Profile":"d0cf3285-cb76-42e1-ba33-8db203007dae","Height":0.01,"Direction":{"X":0.0,"Y":0.0,"Z":1.0},"Reverse Winding":false,"LocalTransform":null,"IsVoid":false}]},"IsElementDefinition":false,"Id":"20472b77-5b83-4096-b6a3-52dcbb7cf80e","Name":null,"associatedIdentities":{"Corridors":[{"id":"76ae45e6-ec8e-444b-a379-04b0e2ebf177","identity":{"Original Geometry":{"discriminator":"Elements.Geometry.Polyline","Vertices":[{"X":5.75,"Y":22.0,"Z":0.0},{"X":5.75,"Y":8.0,"Z":0.0}]}}}]}},"2721b0fc-180e-4d92-921e-905edf28af54":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":10.21,"Y":38.01,"Z":0.0},{"X":-0.21,"Y":38.01,"Z":0.0},{"X":-0.21,"Y":21.99,"Z":0.0},{"X":10.21,"Y":21.99,"Z":0.0}]},"Voids":null,"Id":"2721b0fc-180e-4d92-921e-905edf28af54","Name":"Thicker Offset"},"789b4517-c7b8-4d95-94aa-bcf68f302bc2":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":10.21,"Y":8.01,"Z":0.0},{"X":-0.21,"Y":8.01,"Z":0.0},{"X":-0.21,"Y":-8.01,"Z":0.0},{"X":10.21,"Y":-8.01,"Z":0.0}]},"Voids":null,"Id":"789b4517-c7b8-4d95-94aa-bcf68f302bc2","Name":"Thicker Offset"},"d6474434-a3cf-44e6-94bd-29d6054fe1cb":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":9.25164,"Y":30.0,"Z":0.0},{"X":7.75164,"Y":30.0,"Z":0.0},{"X":7.64952,"Y":0.0,"Z":0.0},{"X":9.14953,"Y":0.0,"Z":0.0}]},"Voids":[],"Id":"d6474434-a3cf-44e6-94bd-29d6054fe1cb","Name":null},"994c6715-e856-4aed-afc0-c5fc5726420b":{"discriminator":"Elements.Floor","Thickness":0.005,"Profile":"d6474434-a3cf-44e6-94bd-29d6054fe1cb","Openings":[],"Level":null,"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,-5.0]}},"Material":"9f05bd39-2950-40cc-a11c-bbaafc475de5","Representation":{"SolidOperations":[{"discriminator":"Elements.Geometry.Solids.Extrude","Profile":"d6474434-a3cf-44e6-94bd-29d6054fe1cb","Height":0.005,"Direction":{"X":0.0,"Y":0.0,"Z":1.0},"Reverse Winding":false,"LocalTransform":null,"IsVoid":false}]},"IsElementDefinition":false,"Id":"994c6715-e856-4aed-afc0-c5fc5726420b","Name":null},"fb041a08-bfb4-479e-a8de-195278fe5433":{"discriminator":"Elements.LevelElements","Elements":["5b6ec190-bf9e-47a3-b8e9-718883352cfd","2721b0fc-180e-4d92-921e-905edf28af54","789b4517-c7b8-4d95-94aa-bcf68f302bc2","994c6715-e856-4aed-afc0-c5fc5726420b"],"Level":"e7f8302c-cdc5-4bb2-94e0-5d7934c60b93","Id":"fb041a08-bfb4-479e-a8de-195278fe5433","Name":"B1"},"da59afe9-f550-496c-9b45-b3d22d4f1742":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":10.21,"Y":38.01,"Z":0.0},{"X":-0.21,"Y":38.01,"Z":0.0},{"X":-0.21,"Y":21.99,"Z":0.0},{"X":10.21,"Y":21.99,"Z":0.0}]},"Voids":null,"Id":"da59afe9-f550-496c-9b45-b3d22d4f1742","Name":"Thicker Offset"},"023eac67-e3ba-4c28-8198-29d29299a250":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":10.21,"Y":8.01,"Z":0.0},{"X":-0.21,"Y":8.01,"Z":0.0},{"X":-0.21,"Y":-8.01,"Z":0.0},{"X":10.21,"Y":-8.01,"Z":0.0}]},"Voids":null,"Id":"023eac67-e3ba-4c28-8198-29d29299a250","Name":"Thicker Offset"},"278866e1-e674-419e-9bee-d6071e4f3748":{"discriminator":"Elements.Geometry.Profile","Perimeter":{"discriminator":"Elements.Geometry.Polygon","Vertices":[{"X":9.25164,"Y":30.0,"Z":0.0},{"X":7.75164,"Y":30.0,"Z":0.0},{"X":7.64952,"Y":0.0,"Z":0.0},{"X":9.14953,"Y":0.0,"Z":0.0}]},"Voids":[],"Id":"278866e1-e674-419e-9bee-d6071e4f3748","Name":null},"4693abed-5fdb-4009-a8c7-045107e8f04c":{"discriminator":"Elements.Floor","Thickness":0.005,"Profile":"278866e1-e674-419e-9bee-d6071e4f3748","Openings":[],"Level":null,"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Material":"9f05bd39-2950-40cc-a11c-bbaafc475de5","Representation":{"SolidOperations":[{"discriminator":"Elements.Geometry.Solids.Extrude","Profile":"278866e1-e674-419e-9bee-d6071e4f3748","Height":0.005,"Direction":{"X":0.0,"Y":0.0,"Z":1.0},"Reverse Winding":false,"LocalTransform":null,"IsVoid":false}]},"IsElementDefinition":false,"Id":"4693abed-5fdb-4009-a8c7-045107e8f04c","Name":null},"5f5dc0a4-ad21-4fd0-82f5-b95724d37f6f":{"discriminator":"Elements.LevelElements","Elements":["d0cf3285-cb76-42e1-ba33-8db203007dae","da59afe9-f550-496c-9b45-b3d22d4f1742","023eac67-e3ba-4c28-8198-29d29299a250","4693abed-5fdb-4009-a8c7-045107e8f04c"],"Level":"ff6eaf49-0e35-490d-8e74-d42766c5f3f2","Id":"5f5dc0a4-ad21-4fd0-82f5-b95724d37f6f","Name":"Ground Level"}}}
Loading
Loading