[TestCase(DungeonShapeType.RANDOMshape, 4, 1)] //exactly enough capacity public void Test_Dungeon_Constructor(DungeonShapeType shape, int rooms, int cap) { // Create the dungeon variable Dungeon dungeon = null; Exception exc = null; //Pre-Condition if (rooms < 3 || cap < 1) { //Check if constructor throws an exception when pre-condition is not met Assert.Throws <ArgumentException>(() => new Dungeon(shape, rooms, cap)); } //Post-Condition else { //Try creating the dungeon try { dungeon = new Dungeon(shape, rooms, cap); } catch (Exception e) { exc = e; } Assert.IsTrue(dungeon != null); Assert.IsTrue(HelperPredicates.AllIdsAreUnique(dungeon)); //Check if all ids are unique Assert.IsTrue(dungeon.Rooms.Count == rooms); //Check the number of rooms Assert.IsTrue(HelperPredicates.Forall(dungeon.Rooms, r => r.Capacity <= cap)); //Check the capacity of each room switch (shape) { case DungeonShapeType.LINEARshape: Assert.IsTrue(HelperPredicates.IsLinear(dungeon)); break; case DungeonShapeType.TREEshape: Assert.IsTrue(HelperPredicates.IsTree(dungeon)); break; case DungeonShapeType.RANDOMshape: Assert.IsTrue(HelperPredicates.HasUniqueStartAndExit(dungeon)); Assert.IsTrue(HelperPredicates.AllReachableFromStart(dungeon)); Assert.IsFalse(HelperPredicates.IsTree(dungeon)); Assert.IsFalse(HelperPredicates.IsLinear(dungeon)); break; } } }
public void Test_IsLinear() { var start = new Room("start", RoomType.STARTroom, 0); var r1 = new Room("r1", RoomType.ORDINARYroom, 10); var r2 = new Room("r2", RoomType.ORDINARYroom, 10); var exit = new Room("exit", RoomType.EXITroom, 0); start.Connect(r1); r1.Connect(r2); r2.Connect(exit); var dungeon = new DummyDungeon(); // start -- r1 -- r2 -- exit dungeon.Rooms.Add(start); dungeon.Rooms.Add(r1); dungeon.Rooms.Add(r2); dungeon.Rooms.Add(exit); Assert.IsFalse(HelperPredicates.IsLinear(dungeon)); dungeon.StartRoom = start; dungeon.ExitRoom = exit; Assert.IsTrue(HelperPredicates.IsLinear(dungeon)); // start -- r1 -- r2 exit r2.Disconnect(exit); Assert.IsFalse(HelperPredicates.IsLinear(dungeon)); // start -- r1 -- r2 -- exit // |___________| r2.Connect(exit); r1.Connect(exit); Assert.IsFalse(HelperPredicates.IsLinear(dungeon)); // start -- r1 ------ exit // |___r2 r1.Disconnect(r2); r2.Disconnect(exit); start.Connect(r2); Assert.IsFalse(HelperPredicates.IsLinear(dungeon)); }