private static void InitFloorToContext(TestFloorPlan floorPlan, Loc size, Rect[] rooms, Rect[] halls, Tuple <char, char>[] links) { floorPlan.InitSize(new Loc(size.X, size.Y)); // 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)); } 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)); } // 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 PlaceRoomsOnFloorIntrusiveHalls() { // place a ring of rooms connected by halls string[] inGrid = { "A.0", ". .", "A#B", ". .", "0.B", }; TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5); for (int ii = 0; ii < gridPlan.RoomCount; ii++) { var gen = new TestFloorPlanGen(((TestGridRoomGen)gridPlan.GetRoom(ii)).Identifier) { ProposedSize = new Loc(2, 2), }; gridPlan.PublicArrayRooms[ii].RoomGen = gen; } gridPlan.PublicHHalls[0][1].SetGen(new TestFloorPlanGen('a')); TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext( gridPlan.Size, new Rect[] { new Rect(0, 0, 2, 2), new Rect(9, 15, 2, 2) }, new Rect[] { new Rect(2, 1, 4, 10), new Rect(6, 6, 3, 10) }, new Tuple <char, char>[] { Tuple.Create('A', 'a'), Tuple.Create('a', 'b'), Tuple.Create('b', 'B') }); ((TestFloorPlanGen)compareFloorPlan.PublicHalls[1].RoomGen).Identifier = 'a'; Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); Moq.Language.ISetupSequentialResult <int> seq = testRand.SetupSequence(p => p.Next(4)); seq = seq.Returns(0); seq = seq.Returns(3); seq = testRand.SetupSequence(p => p.Next(10)); seq = seq.Returns(0); seq = seq.Returns(9); var floorPlan = new TestFloorPlan(); floorPlan.InitSize(gridPlan.Size); Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict); mockMap.SetupGet(p => p.Rand).Returns(testRand.Object); mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan); gridPlan.PlaceRoomsOnFloor(mockMap.Object); TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan); }
public void AddRoomToOutOfBounds(int x, int y) { // attempt to touch out of bounds var floorPlan = new TestFloorPlan(); floorPlan.InitSize(new Loc(22, 14)); Mock <TestFloorPlanGen> gen = new Mock <TestFloorPlanGen>(MockBehavior.Loose); gen.SetupGet(p => p.Draw).Returns(new Rect(x, y, 2, 3)); gen.Object.Identifier = 'A'; // check the rooms Assert.Throws <InvalidOperationException>(() => { floorPlan.AddRoom(gen.Object, false); }); }
public void PlaceRoomsOnFloorDefault() { // place a line of rooms with one default string[] inGrid = { "A#B#C", ". . .", "0.0.0", }; TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5); { var gen = new TestFloorPlanGen('A') { ProposedSize = new Loc(5, 5) }; gridPlan.PublicArrayRooms[0].RoomGen = gen; } { gridPlan.PublicArrayRooms[1].RoomGen = new RoomGenDefault <IFloorPlanTestContext>(); gridPlan.PublicArrayRooms[1].PreferHall = true; } { var gen = new TestFloorPlanGen('B') { ProposedSize = new Loc(5, 5) }; gridPlan.PublicArrayRooms[2].RoomGen = gen; } gridPlan.PublicHHalls[0][0].SetGen(new TestFloorPlanGen('b')); gridPlan.PublicHHalls[1][0].SetGen(new TestFloorPlanGen('c')); TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext( gridPlan.Size, new Rect[] { new Rect(0, 0, 5, 5), new Rect(12, 0, 5, 5) }, new Rect[] { new Rect(6, 0, 1, 1), new Rect(5, 0, 1, 5), new Rect(7, 0, 5, 5) }, new Tuple <char, char>[] { Tuple.Create('A', 'b'), Tuple.Create('b', 'a'), Tuple.Create('a', 'c'), Tuple.Create('c', 'B') }); Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); testRand.Setup(p => p.Next(It.IsAny <int>())).Returns(0); var floorPlan = new TestFloorPlan(); floorPlan.InitSize(gridPlan.Size); Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict); mockMap.SetupGet(p => p.Rand).Returns(testRand.Object); mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan); gridPlan.PlaceRoomsOnFloor(mockMap.Object); // check the rooms Assert.That(floorPlan.RoomCount, Is.EqualTo(compareFloorPlan.RoomCount)); for (int ii = 0; ii < floorPlan.RoomCount; ii++) { FloorRoomPlan plan = floorPlan.PublicRooms[ii]; FloorRoomPlan comparePlan = compareFloorPlan.PublicRooms[ii]; Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen)); Assert.That(plan.Adjacents, Is.EqualTo(comparePlan.Adjacents)); } Assert.That(floorPlan.HallCount, Is.EqualTo(compareFloorPlan.HallCount)); for (int ii = 0; ii < floorPlan.HallCount; ii++) { FloorHallPlan plan = floorPlan.PublicHalls[ii]; FloorHallPlan comparePlan = compareFloorPlan.PublicHalls[ii]; if (ii != 0) { Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen)); } else { // special case for the default Assert.That(plan.RoomGen, Is.TypeOf <RoomGenDefault <IFloorPlanTestContext> >()); Assert.That(plan.RoomGen.Draw, Is.EqualTo(comparePlan.RoomGen.Draw)); } Assert.That(plan.Adjacents, Is.EqualTo(comparePlan.Adjacents)); } }
public void PlaceRoomsOnFloorRing() { // place a ring of rooms connected by halls string[] inGrid = { "A#B", "# #", "D#C", }; TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5); for (int ii = 0; ii < gridPlan.RoomCount; ii++) { var gen = new TestFloorPlanGen(((TestGridRoomGen)gridPlan.GetRoom(ii)).Identifier) { ProposedSize = new Loc(5, 5), }; gridPlan.PublicArrayRooms[ii].RoomGen = gen; } gridPlan.PublicVHalls[0][0].SetGen(new TestFloorPlanGen('a')); gridPlan.PublicVHalls[1][0].SetGen(new TestFloorPlanGen('b')); gridPlan.PublicHHalls[0][0].SetGen(new TestFloorPlanGen('c')); gridPlan.PublicHHalls[0][1].SetGen(new TestFloorPlanGen('d')); TestFloorPlan compareFloorPlan; { var links = new Tuple <char, char>[] { Tuple.Create('A', 'a'), Tuple.Create('a', 'D'), Tuple.Create('B', 'b'), Tuple.Create('b', 'C'), Tuple.Create('A', 'c'), Tuple.Create('c', 'B'), Tuple.Create('D', 'd'), Tuple.Create('d', 'C'), }; compareFloorPlan = TestFloorPlan.InitFloorToContext( gridPlan.Size, new Rect[] { new Rect(0, 0, 5, 5), new Rect(6, 0, 5, 5), new Rect(6, 6, 5, 5), new Rect(0, 6, 5, 5) }, new Rect[] { new Rect(0, 5, 5, 1), new Rect(6, 5, 5, 1), new Rect(5, 0, 1, 5), new Rect(5, 6, 1, 5) }, links); } Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); testRand.Setup(p => p.Next(It.IsAny <int>())).Returns(0); var floorPlan = new TestFloorPlan(); floorPlan.InitSize(gridPlan.Size); Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict); mockMap.SetupGet(p => p.Rand).Returns(testRand.Object); mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan); gridPlan.PlaceRoomsOnFloor(mockMap.Object); 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)); } } }