Example #1
0
        public void testDFSNumberOfVisitedCells2()
        {
            //0     1       10
            //10    8       10
            //10    1       0
            IMap map = new Map(3, 3, 0, 1, 10, 10, 8, 10, 10, 1, 0);

            IMapService service = new MapServiceDFS(map);

            IServiceResult result = service.FindAllRiverSourcesWhichFlowToBothOceans();

            Assert.AreEqual(24, result.TotalCountOfVisitedCells, "Wrong number of visited cells for DFS.");
        }
Example #2
0
        public void testDFSNumberOfVisitedCells1()
        {
            //0     23       246       245     225     205     88
            //114   98       220       129     241     112     254
            //173   207      231       246     125     57      251
            //22    70       105       146     127     113     188
            //55   33        158       107     19      71      137
            //73   92        80        155     161     13      0

            IMap map = new Map(6, 7, 0, 23, 246, 245, 225, 205, 88, 114, 98, 220, 129, 241, 112, 254, 173, 207, 231, 246, 125, 57, 251,
                               22, 70, 105, 146, 127, 113, 188, 55, 33, 158, 107, 19, 71, 137, 73, 92, 80, 155, 161, 13, 0);

            IMapService    service = new MapServiceDFS(map);
            IServiceResult result  = service.FindAllRiverSourcesWhichFlowToBothOceans();

            Assert.AreEqual(220, result.TotalCountOfVisitedCells, "Wrong number of visited cells for DFS.");
        }
Example #3
0
        public void testDFSOneHit()
        {
            //0     23       246       245     225     205     88
            //114   98       220       129     241     112     254
            //173   207      231       246     125     57      251
            //22    70       105       146     127     113     188
            //55   33        158       107     19      71      137
            //73   92        80        155     161     13      0

            IMap map = new Map(6, 7, 0, 23, 246, 245, 225, 205, 88, 114, 98, 220, 129, 241, 112, 254, 173, 207, 231, 246, 125, 57, 251,
                               22, 70, 105, 146, 127, 113, 188, 55, 33, 158, 107, 19, 71, 137, 73, 92, 80, 155, 161, 13, 0);

            IMapService            service = new MapServiceDFS(map);
            IEnumerable <IMapCell> sources = service.FindAllRiverSourcesWhichFlowToBothOceans().Sources;

            Assert.AreEqual(1, sources.Count(), "Wrong number of sources.");
            Assert.IsTrue(sources.Contains(map.GetCell(2, 3)), "Wrong source.");
        }
Example #4
0
        public void testDFSNoHits()
        {
            //0     101       199       139     168     210     45
            //107   104       246       183     115     113     171
            //122   209       42        12      15      7       219
            //41    146       210       1       53      175     210
            //203   62        182       52      163     224     242
            //151   28        105       222     140     196     0

            IMap map = new Map(6, 7, 0, 101, 199, 139, 168, 210, 45, 107, 104, 246, 183, 115, 113, 171, 122, 209, 42, 12, 15, 7, 219, 41, 146, 210, 1, 53, 175, 210,
                               203, 62, 182, 52, 163, 224, 242, 151, 28, 105, 222, 140, 196, 0);

            IMapService service = new MapServiceDFS(map);

            IEnumerable <IMapCell> sources = service.FindAllRiverSourcesWhichFlowToBothOceans().Sources;

            Assert.AreEqual(0, sources.Count(), "Wrong number of sources.");
        }
Example #5
0
        public void testDFSMultipleHits()
        {
            //0     1       10
            //10    8       10
            //10    1       0
            IMap map = new Map(3, 3, 0, 1, 10, 10, 8, 10, 10, 1, 0);

            IMapService service = new MapServiceDFS(map);

            IEnumerable <IMapCell> sources = service.FindAllRiverSourcesWhichFlowToBothOceans().Sources;

            Assert.AreEqual(5, sources.Count(), "Wrong number of sources.");

            Assert.IsTrue(sources.Contains(map.GetCell(1, 1)), "Missing source.");
            Assert.IsTrue(sources.Contains(map.GetCell(1, 0)), "Missing source.");
            Assert.IsTrue(sources.Contains(map.GetCell(2, 0)), "Missing source.");
            Assert.IsTrue(sources.Contains(map.GetCell(0, 2)), "Missing source.");
            Assert.IsTrue(sources.Contains(map.GetCell(1, 2)), "Missing source.");
        }
Example #6
0
        private static IServiceResult DFS(IMap map)
        {
            IMapService service = new MapServiceDFS(map);

            return(service.FindAllRiverSourcesWhichFlowToBothOceans());
        }