private static void InitFloorToContext(TestFloorPlan floorPlan, Rect rect, Rect[] rooms, Rect[] halls, Tuple <char, char>[] links) { floorPlan.InitRect(rect); // a quick way to set up rooms, halls, and connections // a list of rects for rooms, a list of rects for halls for (int ii = 0; ii < rooms.Length; ii++) { var gen = new TestFloorPlanGen((char)('A' + ii)); gen.PrepareDraw(rooms[ii]); floorPlan.PublicRooms.Add(new FloorRoomPlan(gen, new ComponentCollection())); } for (int ii = 0; ii < halls.Length; ii++) { var gen = new TestFloorPlanGen((char)('a' + ii)); gen.PrepareDraw(halls[ii]); floorPlan.PublicHalls.Add(new FloorHallPlan(gen, new ComponentCollection())); } // and finally a list of tuples that link rooms to rooms and halls to halls for (int ii = 0; ii < links.Length; ii++) { bool hall1 = links[ii].Item1 >= 'a'; int index1 = hall1 ? links[ii].Item1 - 'a' : links[ii].Item1 - 'A'; bool hall2 = links[ii].Item2 >= 'a'; int index2 = hall2 ? links[ii].Item2 - 'a' : links[ii].Item2 - 'A'; var link1 = new RoomHallIndex(index1, hall1); var link2 = new RoomHallIndex(index2, hall2); IFloorRoomPlan from1 = floorPlan.GetRoomHall(link1); IFloorRoomPlan from2 = floorPlan.GetRoomHall(link2); from1.Adjacents.Add(link2); from2.Adjacents.Add(link1); } }
public void EraseRoomHallHall() { // erase existent rooms in the middle of a list, checking for room consistency // and adjacency consistency TestFloorPlan floorPlan; { var links = new Tuple <char, char>[] { Tuple.Create('a', 'b'), Tuple.Create('b', 'c'), Tuple.Create('c', 'a'), Tuple.Create('A', 'a'), Tuple.Create('B', 'b'), Tuple.Create('C', 'c'), }; floorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty }, new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty }, links); } TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { Rect.Empty, Rect.Empty, Rect.Empty }, new Rect[] { Rect.Empty, Rect.Empty }, new Tuple <char, char>[] { Tuple.Create('b', 'a'), Tuple.Create('A', 'a'), Tuple.Create('C', 'b') }); ((TestFloorPlanGen)compareFloorPlan.GetRoomHall(new RoomHallIndex(1, true)).RoomGen).Identifier = 'c'; floorPlan.EraseRoomHall(new RoomHallIndex(1, true)); TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan); }
public void TransferBorderToAdjacents(int index, bool isHall, int expectedRoom, int expectedHall) { List <Mock <IRoomGen> > roomGenTarget = new List <Mock <IRoomGen> >(); List <Mock <IPermissiveRoomGen> > hallGenTarget = new List <Mock <IPermissiveRoomGen> >(); var floorPlan = new TestFloorPlan(); floorPlan.InitSize(new Loc(22, 14)); for (int ii = 0; ii < 5; ii++) { Mock <IRoomGen> roomGen = new Mock <IRoomGen>(MockBehavior.Strict); roomGen.SetupGet(p => p.Draw).Returns(Rect.Empty); if (ii == 1 || ii == 3) { roomGen.Setup(p => p.ReceiveOpenedBorder(It.IsAny <IRoomGen>(), It.IsAny <Dir4>())); roomGenTarget.Add(roomGen); } var roomPlan = new FloorRoomPlan(roomGen.Object); roomPlan.Adjacents.Add(new RoomHallIndex(1, false)); roomPlan.Adjacents.Add(new RoomHallIndex(3, false)); roomPlan.Adjacents.Add(new RoomHallIndex(1, true)); roomPlan.Adjacents.Add(new RoomHallIndex(3, true)); floorPlan.PublicRooms.Add(roomPlan); } for (int ii = 0; ii < 5; ii++) { Mock <IPermissiveRoomGen> roomGen = new Mock <IPermissiveRoomGen>(MockBehavior.Strict); roomGen.SetupGet(p => p.Draw).Returns(Rect.Empty); if (ii == 1 || ii == 3) { roomGen.Setup(p => p.ReceiveOpenedBorder(It.IsAny <IRoomGen>(), It.IsAny <Dir4>())); hallGenTarget.Add(roomGen); } var roomPlan = new FloorHallPlan(roomGen.Object); roomPlan.Adjacents.Add(new RoomHallIndex(1, false)); roomPlan.Adjacents.Add(new RoomHallIndex(3, false)); roomPlan.Adjacents.Add(new RoomHallIndex(1, true)); roomPlan.Adjacents.Add(new RoomHallIndex(3, true)); floorPlan.PublicHalls.Add(roomPlan); } IRoomGen from = floorPlan.GetRoomHall(new RoomHallIndex(index, isHall)).RoomGen; floorPlan.TransferBorderToAdjacents(new RoomHallIndex(index, isHall)); for (int ii = 0; ii < roomGenTarget.Count; ii++) { if (ii >= roomGenTarget.Count - expectedRoom) { roomGenTarget[ii].Verify(p => p.ReceiveOpenedBorder(from, It.IsAny <Dir4>()), Times.Exactly(1)); } else { roomGenTarget[ii].Verify(p => p.ReceiveOpenedBorder(from, It.IsAny <Dir4>()), Times.Exactly(0)); } } for (int ii = 0; ii < hallGenTarget.Count; ii++) { if (ii >= hallGenTarget.Count - expectedHall) { hallGenTarget[ii].Verify(p => p.ReceiveOpenedBorder(from, It.IsAny <Dir4>()), Times.Exactly(1)); } else { hallGenTarget[ii].Verify(p => p.ReceiveOpenedBorder(from, It.IsAny <Dir4>()), Times.Exactly(0)); } } }