Пример #1
0
        public void DetectBlobsSingle()
        {
            // single blob
            string[] inGrid =
            {
                "XXXXXX",
                "X..XXX",
                "X....X",
                "X.XXXX",
                "XXXXXX",
            };

            string[] outGrid =
            {
                "@@@@@@",
                "@AA@@@",
                "@AAAA@",
                "@A@@@@",
                "@@@@@@",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            int[][] blob = GridTest.InitIntGrid(outGrid);

            var compareBlobs = new List<BlobMap.Blob> { new BlobMap.Blob(new Rect(1, 1, 4, 3), 7) };

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            BlobMap result = Detection.DetectBlobs(new Rect(0, 0, map.Length, map[0].Length), LocTest);
            Assert.That(result.Map, Is.EqualTo(blob));
            Assert.That(result.Blobs, Is.EqualTo(compareBlobs));
        }
Пример #2
0
        public void IterateAutomataIterations3()
        {
            string[] inGrid =
            {
                "XXXXX",
                "X...X",
                "X...X",
                "X...X",
                "XXXXX",
            };

            string[] outGrid =
            {
                "XXXXX",
                "XXXXX",
                "XXXXX",
                "XXXXX",
                "XXXXX",
            };

            bool[][] map     = GridTest.InitBoolGrid(inGrid);
            bool[][] compare = GridTest.InitBoolGrid(outGrid);

            bool[][] result = NoiseGen.IterateAutomata(map, CellRule.None, CellRule.Gte4, 3);
            Assert.That(result, Is.EqualTo(compare));
        }
Пример #3
0
        public void DetectBlobsNone()
        {
            // no blob
            string[] inGrid =
            {
                "XXXXXX",
                "XXXXXX",
                "XXXXXX",
                "XXXXXX",
            };

            string[] outGrid =
            {
                "@@@@@@",
                "@@@@@@",
                "@@@@@@",
                "@@@@@@",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            int[][] blob = GridTest.InitIntGrid(outGrid);

            List<BlobMap.Blob> compareBlobs = new List<BlobMap.Blob>();

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            BlobMap result = Detection.DetectBlobs(new Rect(0, 0, map.Length, map[0].Length), LocTest);
            Assert.That(result.Map, Is.EqualTo(blob));
            Assert.That(result.Blobs, Is.EqualTo(compareBlobs));
        }
Пример #4
0
        public void DetectDisconnectErasureTolerant()
        {
            // total erasure (with tolerance)
            string[] inGrid =
            {
                "XXXXXX",
                "X....X",
                "X....X",
                "XXXXXX",
            };

            string[] blobGrid =
            {
                "....",
                "....",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            bool[][] blob = GridTest.InitBoolGrid(blobGrid);

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            bool BlobTest(Loc loc) => blob[loc.X][loc.Y];
            bool result = Detection.DetectDisconnect(new Rect(0, 0, map.Length, map[0].Length), LocTest, Loc.One, new Loc(blob.Length, blob[0].Length), BlobTest, false);
            Assert.That(result, Is.EqualTo(false));
        }
Пример #5
0
        public void DetectDisconnectSome()
        {
            // disconnect
            string[] inGrid =
            {
                "XXXXXX",
                "X....X",
                "X....X",
                "XXXXXX",
            };

            string[] blobGrid =
            {
                "..",
                "..",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            bool[][] blob = GridTest.InitBoolGrid(blobGrid);

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            bool BlobTest(Loc loc) => blob[loc.X][loc.Y];
            bool result = Detection.DetectDisconnect(new Rect(0, 0, map.Length, map[0].Length), LocTest, new Loc(2, 1), new Loc(blob.Length, blob[0].Length), BlobTest, false);
            Assert.That(result, Is.EqualTo(true));
        }
Пример #6
0
        public void DetectBlobsCorners()
        {
            // diagonal attached blobs
            string[] inGrid =
            {
                "..XX..",
                "..XX..",
                "XXXXXX",
                "XXXXXX",
            };

            string[] outGrid =
            {
                "AA@@BB",
                "AA@@BB",
                "@@@@@@",
                "@@@@@@",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);
            int[][] blob = GridTest.InitIntGrid(outGrid);

            var compareBlobs = new List<BlobMap.Blob>
            {
                new BlobMap.Blob(new Rect(0, 0, 2, 2), 4),
                new BlobMap.Blob(new Rect(4, 0, 2, 2), 4),
            };

            bool LocTest(Loc loc) => map[loc.X][loc.Y];
            BlobMap result = Detection.DetectBlobs(new Rect(0, 0, map.Length, map[0].Length), LocTest);
            Assert.That(result.Map, Is.EqualTo(blob));
            Assert.That(result.Blobs, Is.EqualTo(compareBlobs));
        }
Пример #7
0
        public void IterateAutomataSingle7(CellRule rule, bool expected)
        {
            // test to verify all neighbors are influencing decision correctly
            string[] inGrid =
            {
                "X..",
                "...",
                "...",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);

            bool[][] result = NoiseGen.IterateAutomata(map, CellRule.None, rule, 1);
            Assert.That(result[1][1], Is.EqualTo(expected));
        }
Пример #8
0
        public void GetWallDir(int gridType, Dir4 result)
        {
            // no correct grounds
            string[] inGrid =
            {
                "XXX",
                "XXX",
                "XXX",
            };

            switch (gridType)
            {
                case 1:
                    // one correct ground, all valid block
                    inGrid = new string[]
                    {
                        "XXX",
                        "XXX",
                        "X.X",
                    };
                    break;
                case 2:
                    inGrid = new string[]
                    {
                        "XXX",
                        ".XX",
                        "XXX",
                    };
                    break;
                case 3:
                    // multiple correct ground
                    inGrid = new string[]
                    {
                        "XXX",
                        ".XX",
                        "X.X",
                    };
                    break;
                case 4:
                    // one correct ground, but one invalid
                    inGrid = new string[]
                    {
                        "XXX",
                        "~XX",
                        "X.X",
                    };
                    break;
                case 5:
                    // one correct ground, one crucial diagonal an invalid block
                    inGrid = new string[]
                    {
                        "XX~",
                        "XXX",
                        "X.X",
                    };
                    break;
                case 6:
                    // one correct ground, both noncrucial diagonal an invalid block
                    inGrid = new string[]
                    {
                        "XXX",
                        "XXX",
                        "~.~",
                    };
                    break;
                default:
                    break;
            }

            char[][] map = GridTest.InitGrid(inGrid);

            bool CheckBlock(Loc testLoc) => map[testLoc.X][testLoc.Y] == 'X';
            bool CheckGround(Loc testLoc) => map[testLoc.X][testLoc.Y] == '.';

            LocRay4 locRay = Detection.GetWallDir(new Loc(1), CheckBlock, CheckGround);
            Assert.That(locRay, Is.EqualTo(new LocRay4(new Loc(1), result)));
        }