Skip to content

Commit

Permalink
add comments to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaSloboda committed Aug 30, 2023
1 parent ab9b013 commit 14fa711
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 15 deletions.
11 changes: 9 additions & 2 deletions LayoutFunctions/ClassroomLayout/test/ClassroomLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@ public class ClassroomLayoutTests
[Fact]
public void ClassroomConfigurations()
{
// test with one room for each configuration
// 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);
Expand All @@ -44,7 +51,7 @@ public void ClassroomConfigurations()
}
}

// room with 3 desks
// 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();
Expand Down
9 changes: 8 additions & 1 deletion LayoutFunctions/LoungeLayout/test/LoungeLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@ public class LoungeLayoutTests
[Fact]
public void LoungeConfigurations()
{
// test with one room for each configuration
// 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("LoungeConfigurations.json");

// Get the result of LoungeLayout.Execute()
var (output, spacePlanningModel) = LoungeLayoutTest(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 == "Lounge").OrderBy(b => b.Boundary.Perimeter.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.Width < boundary.Bounds.YSize);

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,31 @@ public class MeetingRoomLayoutTests
[Fact]
public void MeetingRoomConfigurations()
{
// test with one room for each configuration
// 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("ConferenceRoomConfigurations.json");

// Get the result of MeetingRoomLayout.Execute()
var (output, spacePlanningModel) = MeetingRoomLayoutTest(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 == "Meeting Room").OrderBy(b => b.Boundary.Perimeter.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.Width < boundary.Bounds.YSize);

// Look for all the furniture placed within the room
var offsetedBox = boundary.Bounds.Offset(0.1);
offsetedBox.Extend(new Vector3(offsetedBox.Min.X, offsetedBox.Min.Y, offsetedBox.Min.Z - 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@ public class OpenCollaborationLayoutTests
[Fact]
public void OpenCollaborationConfigurations()
{
// Test with a separate "Space Planning Zones" model 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("OpenCollaborationConfigurations.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);

// Check each configuration separately due to the impossibility of predicting a specific order of configurations for multiple rooms in the same building
foreach (var config in configs)
{
// Get the result of OpenCollaborationLayout.Execute()
var (output, spacePlanningModel) = OpenCollaborationLayoutTest(testName, config.Key, levelsModel, circulationModel, input);
var elements = output.Model.AllElementsOfType<ElementInstance>();

// Confirm that the size of the room covers the size of the corresponding configuration
var boundary = spacePlanningModel.AllElementsOfType<SpaceBoundary>().Where(z => z.Name == "Open Collaboration").OrderBy(b => b.Boundary.Perimeter.Center().Y).First();

Assert.True(config.Value.Depth < boundary.Bounds.XSize && config.Value.Width < boundary.Bounds.YSize);

// 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.Value.ContentItems)
{
var boundaryElement = boundaryElements.FirstOrDefault(be => be.AdditionalProperties.TryGetValue("gltfLocation", out var gltfLocation) && gltfLocation.ToString() == contentItem.Url);
Expand All @@ -45,9 +52,9 @@ public void OpenCollaborationConfigurations()
}

private (OpenCollaborationLayoutOutputs output, Model spacePlanningModel) OpenCollaborationLayoutTest(
string testName,
string configName,
Model levelsModel,
string testName,
string configName,
Model levelsModel,
Model circulationModel,
OpenCollaborationLayoutInputs input)
{
Expand Down
20 changes: 17 additions & 3 deletions LayoutFunctions/OpenOfficeLayout/test/OpenOfficeLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class OpenOfficeLayoutTests
[Fact]
public void OpenOfficeConfigurations()
{
// Test to verify the use of all possible desk configurations with some input parameter values
// to check that every piece of expected content exists in a room of a matching desk type
var testName = "Configurations";
var configs = LayoutStrategies.GetConfigurations("OpenOfficeDeskConfigurations.json");
var spacePlanningModel = Model.FromJson(System.IO.File.ReadAllText($"{INPUT}/{testName}/Space Planning Zones.json"));
Expand All @@ -26,36 +28,48 @@ public void OpenOfficeConfigurations()
var columnsModel = Model.FromJson(System.IO.File.ReadAllText($"{INPUT}/{testName}/Columns.json"));
var input = GetInput(testName);

// Check each value of the ColumnAvoidanceStrategy parameter separately
foreach (var columnAvoidanceStrategy in Enum.GetNames(typeof(OpenOfficeLayoutInputsColumnAvoidanceStrategy)))
{
// Get the result of OpenOfficeLayout.Execute()
var output = OpenOfficeLayoutTest(testName, columnAvoidanceStrategy, spacePlanningModel, levelsModel, circulationModel, columnsModel, input);
var elements = output.Model.AllElementsAssignableFromType<ElementInstance>().Where(e => e.BaseDefinition is not Column).ToList();

// "Open Collaboration" type rooms located inside "Open Office" rooms
var openCollabBoundaries = output.Model.AllElementsOfType<SpaceBoundary>().Where(b => b.Name == "Open Collaboration");

// Get rooms with each desk type on the Y axis, and with some variation of other input parameters on the X axis
var boundaries = spacePlanningModel.AllElementsOfType<SpaceBoundary>().Where(b => b.Name == "Open Office").OrderBy(b => b.Boundary.Perimeter.Center().Y).ThenBy((b => b.Boundary.Perimeter.Center().X)).ToList();

// Get data about the expected result for each room for this ColumnAvoidanceStrategy type
var expectedResults = GetTestResults(testName, columnAvoidanceStrategy.Replace("_", ""));

for (int i = 0; i < boundaries.Count(); i++)
{
// Verify that the configuration for the expected desk type exists
var boundary = boundaries[i];
var expectedResult = expectedResults[i];
var config = configs.FirstOrDefault(c => c.Key == expectedResult.DeskType).Value;
Assert.NotNull(config);

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

// Check items
// Check that the room has the required number of desks of the same type as in the configuration
foreach (var contentItem in config.ContentItems)
{
// check the number of desks
var suitableElements = boundaryElements.Where(be => be.AdditionalProperties.TryGetValue("gltfLocation", out var gltfLocation) && gltfLocation.ToString() == contentItem.Url).ToList();
Assert.True(suitableElements.Count() >= expectedResult.Count);

// delete checked desks
var expectedElements = suitableElements.SkipLast(suitableElements.Count() - expectedResult.Count);
boundaryElements.RemoveAll(b => expectedElements.Contains(b));
}

// Check open collab areas
// Check that the resulting "Open Collaboration" area for this room is the same as expected
var suitableCollabBoundaries = openCollabBoundaries.Where(b => boundary.Boundary.Perimeter.Contains(b.Boundary.Perimeter.Centroid()));
Assert.Equal(suitableCollabBoundaries.Count(), expectedResult.CollabCount);
Assert.True(suitableCollabBoundaries.Sum(b => b.Area).ApproximatelyEquals(expectedResult.CollabArea, 0.2));
Expand All @@ -64,7 +78,7 @@ public void OpenOfficeConfigurations()
}

private OpenOfficeLayoutOutputs OpenOfficeLayoutTest(
string testName,
string testName,
string columnAvoidanceStrategyName,
Model spacePlanningModel,
Model levelsModel,
Expand Down
9 changes: 8 additions & 1 deletion LayoutFunctions/PantryLayout/test/PantryLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@ public class PantryLayoutTests
[Fact]
public void PantryConfigurations()
{
// test with one room for each configuration
// 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("PantryConfigurations.json");

// Get the result of PantryLayout.Execute()
var (output, spacePlanningModel) = PantryLayoutTest(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 == "Pantry").OrderBy(b => b.Boundary.Perimeter.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.Width < boundary.Bounds.XSize);

// Look for all the furniture placed within the room
var offsetedBox = boundary.Bounds.Offset(0.02);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@ public class PhoneBoothLayoutTests
[Fact]
public void PhoneBoothConfigurations()
{
// test with one room for each configuration
// 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("PhoneBoothConfigurations.json");

// Get the result of PhoneBoothLayout.Execute()
var (output, spacePlanningModel) = PhoneBoothLayoutTest(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 == "Phone Booth").OrderBy(b => b.Boundary.Perimeter.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.Width < boundary.Bounds.YSize);

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@ public class PrivateOfficeLayoutTests
[Fact]
public void PrivateOfficeConfigurations()
{
// test with one room for each configuration
// 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("PrivateOfficeConfigurations.json");

// Get the result of PrivateOfficeLayout.Execute()
var (output, spacePlanningModel) = PrivateOfficeLayoutTest(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 == "Private Office").OrderBy(b => b.Boundary.Perimeter.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.Width < boundary.Bounds.YSize);

// 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);
Expand Down
Loading

0 comments on commit 14fa711

Please sign in to comment.