Skip to content

Commit 3c0ff42

Browse files
committed
Add contains room method
1 parent e4f0eeb commit 3c0ff42

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/ManiaMap.Tests/TestDoorConnection.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,22 @@ public void TestGetConnectingRoom()
5353
Assert.AreEqual(connection.GetConnectingRoom(new Uid(int.MaxValue)), new Uid(-1, -1, -1));
5454
}
5555
}
56+
57+
[TestMethod]
58+
public void TestContainsRoom()
59+
{
60+
var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine);
61+
Assert.IsTrue(results.Success);
62+
var layout = results.GetOutput<Layout>("Layout");
63+
64+
foreach (var connection in layout.DoorConnections.Values)
65+
{
66+
var toRoom = connection.ToRoom;
67+
var fromRoom = connection.FromRoom;
68+
Assert.IsTrue(connection.ContainsRoom(toRoom));
69+
Assert.IsTrue(connection.ContainsRoom(fromRoom));
70+
Assert.IsFalse(connection.ContainsRoom(new Uid(-1, -1, -1)));
71+
}
72+
}
5673
}
5774
}

src/ManiaMap/DoorConnection.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,14 @@ public Uid GetConnectingRoom(Uid roomId)
111111
return FromRoom;
112112
return new Uid(-1, -1, -1);
113113
}
114+
115+
/// <summary>
116+
/// Returns true if the door connections "from room" or "to room" matches the specified room ID.
117+
/// </summary>
118+
/// <param name="roomId">The room ID.</param>
119+
public bool ContainsRoom(Uid roomId)
120+
{
121+
return roomId == FromRoom || roomId == ToRoom;
122+
}
114123
}
115124
}

0 commit comments

Comments
 (0)