示例#1
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));
        }
示例#2
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));
        }
示例#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));
        }