public void ReturnToRoomTest() { Room testRoom = new Room() { AreaType = "Room", ID = 3, State = Room.RoomState.Dirty, Position = new Vector2(2, 0) }; Restaurant restaurant = new Restaurant() { AreaType = "Restaurant", Position = new Vector2(3, 4) }; hotelRooms.Add(testRoom); hotel.Areas.AddRange(hotelRooms); hotel.Areas.Add(restaurant); person.Room = testRoom; Node restaurantNode = new Node(restaurant.Position); Node personNode = new Node(person.Position); Node roomNode = new Node(testRoom.Position); personNode.Edges.Add(roomNode, 1); personNode.Edges.Add(restaurantNode, 1); restaurantNode.Edges.Add(personNode, 1); roomNode.Edges.Add(personNode, 1); simplePath.Add(personNode); simplePath.Add(roomNode); GameTime gameTime = new GameTime(); var prop = person.GetType().GetField("_passedTimeSinceUpdate", BindingFlags.NonPublic | BindingFlags.Instance); prop.SetValue(person, person.WaitingTime / HotelEventManager.HTE_Factor); person.ReturnToRoom(gameTime, simplePath, hotel); Assert.AreEqual(testRoom.Position, person.Destination); }
public void CheckCinemaTest() { Cinema cinema = new Cinema() { Position = new Vector2(3, 0) }; Vector2 wachtVector = new Vector2(2, 0); person.Position = new Vector2(1, 0); person.Destination = cinema.Position; Node a = new Node(person.Position); Node b = new Node(wachtVector); Node c = new Node(cinema.Position); c.Edges.Add(a, 1); a.Edges.Add(c, 1); b.Edges.Add(a, 1); a.Edges.Add(b, 1); cinema.Started = true; SimplePath simplePath = new SimplePath(); simplePath.Add(a); simplePath.Add(b); simplePath.Add(c); person.CheckCinema(simplePath, cinema); Assert.AreEqual(wachtVector, person.Destination); }
public void SearchRoomTest_State() { Room testRoom = new Room() { AreaType = "Room", ID = 3, State = Room.RoomState.Dirty, Position = new Vector2(2, 0) }; hotelRooms.Add(testRoom); Queue <Room> rooms = new Queue <Room>(); hotel.Areas.AddRange(hotelRooms); cleaner.Position = new Vector2(1, 0); Node cleanerNode = new Node(cleaner.Position); Node roomNode = new Node(testRoom.Position); cleanerNode.Edges.Add(roomNode, 1); roomNode.Edges.Add(cleanerNode, 1); simplePath.Add(cleanerNode); simplePath.Add(roomNode); cleaner.SearchRoom(hotel, rooms); Assert.AreEqual(testRoom, rooms.First()); }
public void CheckEventsTest_CheckOut() { HotelEvent evt = new HotelEvent() { EventType = HotelEventType.CHECK_OUT, Data = new Dictionary <string, string> { { "Gast", "1" } } }; listener.Events.Add(evt); hotel.Areas.Add(lobby); Node n1 = new Node(lobby.Position); Node n2 = new Node(customers.Find(id => id.ID == 1).Position); n1.Edges.Add(n2, 1); n2.Edges.Add(n1, 1); simplePath.Add(n1); simplePath.Add(n2); eventChecker.CheckEvents(simplePath, hotel, persons, reception, customers, listener, lobby, elevator, cleaner, cleaners, gameTime, RoomQueue); Assert.AreEqual(1, customers.Count); }
public void AddNull_NoExceptions_Test() { path.Add(null); }
/// <summary> /// adds edges to every node and adds every node to the graph in simplePath /// </summary> /// <param name="simplePath"></param> public void AddToGraph(SimplePath simplePath) { List <Area> noEdges = new List <Area>(); List <Node> transportationAreas = new List <Node>(); int maxX = 0; foreach (Area area in Areas) { if (area.AreaType == "Elevator" || area.AreaType == "Stairs") { transportationAreas.AddRange((area as TransportationArea).GetInternalNodes()); if (area.GetType() == typeof(Stairs)) { maxX = (int)area.Position.X; } } else { noEdges.Add(area); } } Node prevNode = null; List <Node> toAdd = new List <Node>(); foreach (Area area in noEdges.OrderBy(n => n.Position.Y).ThenBy(n => n.Position.X)) { Node positionNode = new Node(new Vector2(area.Position.X, area.Position.Y)); if (prevNode != null && positionNode.Value.Y != prevNode.Value.Y) { prevNode = null; } if (prevNode != null) { positionNode.Edges.Add(prevNode, 1); } else { positionNode.Edges.Add(transportationAreas.Find(ta => ta.Value == new Vector2(0, positionNode.Value.Y)), (int)positionNode.Value.X); } toAdd.Add(positionNode); prevNode = positionNode; } prevNode = null; foreach (Node node in toAdd.OrderBy(n => n.Value.Y).ThenByDescending(n => n.Value.X)) { if (prevNode != null && node.Value.Y != prevNode.Value.Y) { prevNode = null; } if (prevNode != null) { node.Edges.Add(prevNode, 1); } else { node.Edges.Add(transportationAreas.Find(ta => ta.Value == new Vector2(maxX, node.Value.Y)), maxX - (int)node.Value.X); } prevNode = node; } foreach (Node node in toAdd) { if (node.Edges.Any(e => e.Key.Value.X == 0)) { transportationAreas.Where(n => n.Value == node.Edges.Where(k => k.Key.Value.X == 0).First().Key.Value).First().Edges.Add(node, 1); } if (node.Edges.Any(e => e.Key.Value.X == maxX)) { transportationAreas.Where(n => n.Value == node.Edges.Where(k => k.Key.Value.X == maxX).First().Key.Value).First().Edges.Add(node, 1); } simplePath.Add(node); } foreach (Node node in transportationAreas) { simplePath.Add(node); } }