Ejemplo n.º 1
0
        public void ChoosePossibleStartsTwoReqsOverlapRestricted()
        {
            // two overlapping sidereqs, 3 tiles each, two allowed
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(2)).Returns(0);
            testRand.Setup(p => p.Next(1)).Returns(0);
            var roomGen = new TestRoomGen <ITiledGenContext>();

            bool[]          permittedRange = { true, false, false, true, true };
            List <IntRange> sideReqs       = new List <IntRange>
            {
                new IntRange(4, 7),
                new IntRange(5, 8),
            };
            List <HashSet <int> > compare = new List <HashSet <int> >();
            HashSet <int>         set     = new HashSet <int> {
                4
            };

            compare.Add(set);
            set = new HashSet <int> {
                7
            };
            compare.Add(set);

            List <HashSet <int> > result = roomGen.PublicChoosePossibleStarts(testRand.Object, 4, permittedRange, sideReqs);

            Assert.That(result, Is.EqualTo(compare));
            testRand.Verify(p => p.Next(2), Times.Exactly(1));
            testRand.Verify(p => p.Next(1), Times.Exactly(1));
        }
Ejemplo n.º 2
0
        public void SetRoomBordersSemiBlocked()
        {
            var roomGen = new TestRoomGen <ITiledGenContext>();

            string[] inGrid =
            {
                "XXXXXXXX",
                "XXX..X.X",
                "XX.....X",
                "XX....XX",
                "XX..XXXX",
                "XXXXXXXX",
                "XXXXXXXX",
            };

            TestGenContext testContext = TestGenContext.InitGridToContext(inGrid);
            Mock <IRandom> testRand    = new Mock <IRandom>(MockBehavior.Strict);

            roomGen.PrepareSize(testRand.Object, new Loc(5, 4));
            roomGen.SetLoc(new Loc(2, 1));

            roomGen.SetRoomBorders(testContext);

            Assert.That(roomGen.PublicOpenedBorder[Dir4.Down], Is.EqualTo(new bool[] { true, true, false, false, false }));
            Assert.That(roomGen.PublicOpenedBorder[Dir4.Left], Is.EqualTo(new bool[] { false, true, true, true }));
            Assert.That(roomGen.PublicOpenedBorder[Dir4.Up], Is.EqualTo(new bool[] { false, true, true, false, true }));
            Assert.That(roomGen.PublicOpenedBorder[Dir4.Right], Is.EqualTo(new bool[] { true, true, false, false }));
        }
Ejemplo n.º 3
0
        public void ChoosePossibleStartsTwoReqsSuperset(int roll1)
        {
            // two overlapping sidereqs, one superset of the other (rng should make no difference)
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(2)).Returns(roll1);
            testRand.Setup(p => p.Next(1)).Returns(0);
            var roomGen = new TestRoomGen <ITiledGenContext>();

            bool[]          permittedRange = { true, true, true, true, true };
            List <IntRange> sideReqs       = new List <IntRange>
            {
                new IntRange(4, 9),
                new IntRange(6, 8),
            };
            List <HashSet <int> > compare = new List <HashSet <int> >();
            HashSet <int>         set     = new HashSet <int> {
                6, 7
            };

            compare.Add(set);

            List <HashSet <int> > result = roomGen.PublicChoosePossibleStarts(testRand.Object, 4, permittedRange, sideReqs);

            Assert.That(result, Is.EqualTo(compare));
            testRand.Verify(p => p.Next(2), Times.Exactly(1));
            testRand.Verify(p => p.Next(1), Times.Exactly(1));
        }
Ejemplo n.º 4
0
        public void ReceiveFulfillableBorderToFulfill(bool firstHalf, bool secondHalf, bool exception)
        {
            // test with offset, proving previous openedborders are properly transferred
            // test error case, in which no bordertofulfill is opened
            Mock <IRandom> testRand    = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGenTo   = new TestRoomGen <ITiledGenContext>();
            var            roomGenFrom = new TestRoomGen <ITiledGenContext>();

            roomGenTo.PrepareSize(testRand.Object, new Loc(3, 2));
            roomGenTo.SetLoc(new Loc(2, 0));
            roomGenFrom.PrepareSize(testRand.Object, new Loc(4, 2));
            roomGenFrom.SetLoc(new Loc(0, 2));
            roomGenFrom.PublicFulfillableBorder[Dir4.Up][0] = firstHalf;
            roomGenFrom.PublicFulfillableBorder[Dir4.Up][1] = firstHalf;
            roomGenFrom.PublicFulfillableBorder[Dir4.Up][2] = secondHalf;
            roomGenFrom.PublicFulfillableBorder[Dir4.Up][3] = secondHalf;

            if (exception)
            {
                Assert.Throws <ArgumentException>(() => { roomGenTo.ReceiveFulfillableBorder(roomGenFrom, Dir4.Down); });
            }
            else
            {
                roomGenTo.ReceiveFulfillableBorder(roomGenFrom, Dir4.Down);
                var expectedBorderToFulfill = new Dictionary <Dir4, bool[]>
                {
                    [Dir4.Down]  = new bool[] { true, true, false },
                    [Dir4.Left]  = new bool[] { false, false },
                    [Dir4.Up]    = new bool[] { false, false, false },
                    [Dir4.Right] = new bool[] { false, false },
                };
                Assert.That(roomGenTo.PublicBorderToFulfill, Is.EqualTo(expectedBorderToFulfill));
            }
        }
Ejemplo n.º 5
0
        public void PrepareSize(int x, int y, bool exception)
        {
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGen  = new TestRoomGen <ITiledGenContext>();

            // check size
            // opened border and requestable borders are the correct dimensions
            Loc size = new Loc(x, y);

            if (exception)
            {
                Assert.Throws <ArgumentException>(() => { roomGen.PrepareSize(testRand.Object, size); });
            }
            else
            {
                roomGen.PrepareSize(testRand.Object, size);
                Assert.That(roomGen.Draw.Size, Is.EqualTo(size));
                Assert.That(roomGen.PublicOpenedBorder[Dir4.Down].Length, Is.EqualTo(x));
                Assert.That(roomGen.PublicFulfillableBorder[Dir4.Down].Length, Is.EqualTo(x));
                Assert.That(roomGen.PublicOpenedBorder[Dir4.Up].Length, Is.EqualTo(x));
                Assert.That(roomGen.PublicFulfillableBorder[Dir4.Up].Length, Is.EqualTo(x));
                Assert.That(roomGen.PublicOpenedBorder[Dir4.Left].Length, Is.EqualTo(y));
                Assert.That(roomGen.PublicFulfillableBorder[Dir4.Left].Length, Is.EqualTo(y));
                Assert.That(roomGen.PublicOpenedBorder[Dir4.Right].Length, Is.EqualTo(y));
                Assert.That(roomGen.PublicFulfillableBorder[Dir4.Right].Length, Is.EqualTo(y));
            }
        }
Ejemplo n.º 6
0
        public void ChoosePossibleStartsThreeReqsOverlapOneRight(int roll1, int roll2)
        {
            // two separate sidereqs, with one in the middle connecting (with different rng)
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(3)).Returns(roll1);
            testRand.Setup(p => p.Next(2)).Returns(roll2);
            testRand.Setup(p => p.Next(1)).Returns(0);
            var roomGen = new TestRoomGen <ITiledGenContext>();

            bool[]          permittedRange = { true, true, true, true, true };
            List <IntRange> sideReqs       = new List <IntRange>
            {
                new IntRange(4, 6),
                new IntRange(5, 8),
                new IntRange(7, 9),
            };
            List <HashSet <int> > compare = new List <HashSet <int> >();
            HashSet <int>         set     = new HashSet <int> {
                7
            };

            compare.Add(set);
            set = new HashSet <int> {
                4, 5
            };
            compare.Add(set);

            List <HashSet <int> > result = roomGen.PublicChoosePossibleStarts(testRand.Object, 4, permittedRange, sideReqs);

            Assert.That(result, Is.EqualTo(compare));
            testRand.Verify(p => p.Next(3), Times.Exactly(1));
            testRand.Verify(p => p.Next(2), Times.Exactly(1));
            testRand.Verify(p => p.Next(1), Times.Exactly(1));
        }
Ejemplo n.º 7
0
        public void ReceiveOpenedBorder(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, Dir4 dir, int expectedStart, int expectedEnd, bool exception)
        {
            Mock <IRandom> testRand    = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGenTo   = new TestRoomGen <ITiledGenContext>();
            var            roomGenFrom = new TestRoomGen <ITiledGenContext>();

            roomGenTo.PrepareSize(testRand.Object, new Loc(w1, h1));
            roomGenTo.SetLoc(new Loc(x1, y1));
            roomGenFrom.PrepareSize(testRand.Object, new Loc(w2, h2));
            roomGenFrom.SetLoc(new Loc(x2, y2));
            for (int ii = 0; ii < roomGenFrom.PublicOpenedBorder[dir.Reverse()].Length; ii++)
            {
                roomGenFrom.PublicOpenedBorder[dir.Reverse()][ii] = true;
            }

            if (exception)
            {
                Assert.Throws <ArgumentException>(() => { roomGenTo.ReceiveOpenedBorder(roomGenFrom, dir); });
            }
            else
            {
                roomGenTo.ReceiveOpenedBorder(roomGenFrom, dir);
                IntRange newRange = roomGenTo.RoomSideReqs[dir][0];
                Assert.That(newRange, Is.EqualTo(new IntRange(expectedStart, expectedEnd)));
            }
        }
Ejemplo n.º 8
0
        public void ReceiveOpenedBorderToFulfillAlreadyFilled()
        {
            // test error case, in which no borderfill is opened by the openedborder but the tiles already exist
            Mock <IRandom> testRand    = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGenTo   = new TestRoomGen <ITiledGenContext>();
            var            roomGenFrom = new TestRoomGen <ITiledGenContext>();

            roomGenTo.PrepareSize(testRand.Object, new Loc(3, 2));
            roomGenTo.SetLoc(new Loc(2, 0));
            roomGenFrom.PrepareSize(testRand.Object, new Loc(4, 2));
            roomGenFrom.SetLoc(new Loc(0, 2));
            roomGenFrom.PublicOpenedBorder[Dir4.Up][0]    = true;
            roomGenFrom.PublicOpenedBorder[Dir4.Up][1]    = true;
            roomGenTo.PublicBorderToFulfill[Dir4.Down][0] = true;
            roomGenTo.PublicBorderToFulfill[Dir4.Down][1] = true;

            Assert.Throws <ArgumentException>(() => { roomGenTo.ReceiveOpenedBorder(roomGenFrom, Dir4.Down); });
        }
Ejemplo n.º 9
0
        public void ReceiveBorderRange(int rangeStart, int rangeEnd, Dir4 dir, int expectedStart, int expectedEnd, bool exception)
        {
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGen  = new TestRoomGen <ITiledGenContext>();

            roomGen.PrepareSize(testRand.Object, new Loc(5, 7));
            roomGen.SetLoc(new Loc(1, 2));

            if (exception)
            {
                Assert.Throws <ArgumentException>(() => { roomGen.ReceiveBorderRange(new IntRange(rangeStart, rangeEnd), dir); });
            }
            else
            {
                roomGen.ReceiveBorderRange(new IntRange(rangeStart, rangeEnd), dir);
                IntRange newRange = roomGen.RoomSideReqs[dir][0];
                Assert.That(newRange, Is.EqualTo(new IntRange(expectedStart, expectedEnd)));
            }
        }
Ejemplo n.º 10
0
        public void ReceiveBorderRangeToFulfill()
        {
            // test with offset, proving previous openedborders are properly transferred
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGen  = new TestRoomGen <ITiledGenContext>();

            roomGen.PrepareSize(testRand.Object, new Loc(5, 7));
            roomGen.SetLoc(new Loc(2, 3));

            roomGen.ReceiveBorderRange(new IntRange(1, 6), Dir4.Right);
            var expectedBorderToFulfill = new Dictionary <Dir4, bool[]>
            {
                [Dir4.Down]  = new bool[] { false, false, false, false, false },
                [Dir4.Left]  = new bool[] { false, false, false, false, false, false, false },
                [Dir4.Up]    = new bool[] { false, false, false, false, false },
                [Dir4.Right] = new bool[] { true, true, true, false, false, false, false },
            };

            Assert.That(roomGen.PublicBorderToFulfill, Is.EqualTo(expectedBorderToFulfill));
        }
Ejemplo n.º 11
0
        public void ChoosePossibleStartsOneReqRestricted()
        {
            // one sidereq, 3 tiles, one allowed
            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(1)).Returns(0);
            var roomGen = new TestRoomGen <ITiledGenContext>();

            bool[]          permittedRange = { true, false, true, false, true };
            List <IntRange> sideReqs       = new List <IntRange> {
                new IntRange(5, 8)
            };
            List <HashSet <int> > compare = new List <HashSet <int> >();
            HashSet <int>         set     = new HashSet <int> {
                6
            };

            List <HashSet <int> > result = roomGen.PublicChoosePossibleStarts(testRand.Object, 4, permittedRange, sideReqs);

            compare.Add(set);

            Assert.That(result, Is.EqualTo(compare));
            testRand.Verify(p => p.Next(It.IsAny <int>()), Times.Exactly(1));
        }
Ejemplo n.º 12
0
        public void DigAtBorder(Dir4 dir, int scalar, int resultGrid, bool exception)
        {
            var roomGen = new TestRoomGen <ITiledGenContext>();

            string[] inGrid =
            {
                "XXXXXXXX",
                "XX..X..X",
                "XX....XX",
                "XX...XXX",
                "XX....XX",
                "XXXXXXXX",
                "XXXXXXXX",
            };

            string[] outGrid;
            switch (resultGrid)
            {
            case 1:
                outGrid = new string[]
                {
                    "XXXXXXXX",
                    "XX.....X",
                    "XX....XX",
                    "XX...XXX",
                    "XX....XX",
                    "XXXXXXXX",
                    "XXXXXXXX",
                };
                break;

            case 2:
                outGrid = new string[]
                {
                    "XXXXXXXX",
                    "XX..X..X",
                    "XX....XX",
                    "XX.....X",
                    "XX....XX",
                    "XXXXXXXX",
                    "XXXXXXXX",
                };
                break;

            case 3:
                outGrid = new string[]
                {
                    "XXXXXXXX",
                    "XX..X..X",
                    "XX.....X",
                    "XX...X.X",
                    "XX.....X",
                    "XXXXXX.X",
                    "XXXXXXXX",
                };
                break;

            default:
                outGrid = inGrid;
                break;
            }

            TestGenContext testContext   = TestGenContext.InitGridToContext(inGrid);
            TestGenContext resultContext = TestGenContext.InitGridToContext(outGrid);
            Mock <IRandom> testRand      = new Mock <IRandom>(MockBehavior.Strict);

            roomGen.PrepareSize(testRand.Object, new Loc(5, 5));
            roomGen.SetLoc(new Loc(2, 1));

            if (exception)
            {
                Assert.Throws <ArgumentException>(() => { roomGen.DigAtBorder(testContext, dir, scalar); });
            }
            else
            {
                roomGen.DigAtBorder(testContext, dir, scalar);
                Assert.That(testContext.Tiles, Is.EqualTo(resultContext.Tiles));
            }
        }