public void Should_CreateMap_When_ValidLine()
            {
                var line            = ".#.";
                var yPosition       = 1;
                var sut             = new XmasTreeMapRepositoryWrapper();
                var expectedTreeMap = new List <MapLocation>()
                {
                    new MapLocation {
                        Type = PositionType.Open, XPosition = 0, YPosition = yPosition
                    },
                    new MapLocation {
                        Type = PositionType.Tree, XPosition = 1, YPosition = yPosition
                    },
                    new MapLocation {
                        Type = PositionType.Open, XPosition = 2, YPosition = yPosition
                    }
                };

                var resultTreeMap = sut.MapLocationsFromLine(line, yPosition).ToList();

                Assert.That(resultTreeMap.Count() == expectedTreeMap.Count);
                Assert.That(resultTreeMap[0].Type == expectedTreeMap[0].Type);
                Assert.That(resultTreeMap[0].XPosition == expectedTreeMap[0].XPosition);
                Assert.That(resultTreeMap[0].YPosition == expectedTreeMap[0].YPosition);
                Assert.That(resultTreeMap[1].Type == expectedTreeMap[1].Type);
                Assert.That(resultTreeMap[1].XPosition == expectedTreeMap[1].XPosition);
                Assert.That(resultTreeMap[1].YPosition == expectedTreeMap[1].YPosition);
                Assert.That(resultTreeMap[2].Type == expectedTreeMap[2].Type);
                Assert.That(resultTreeMap[2].XPosition == expectedTreeMap[2].XPosition);
                Assert.That(resultTreeMap[2].YPosition == expectedTreeMap[2].YPosition);
            }
            public void Should_ThrowException_When_NullLine()
            {
                string line = null;
                var    sut  = new XmasTreeMapRepositoryWrapper();

                Assert.Throws <ArgumentNullException>(() => sut.MapLocationsFromLine(line, 0));
            }
Ejemplo n.º 3
0
            public void Should_CalculateNumberOfTrees()
            {
                var lines = new List <string>
                {
                    "..##.......",
                    "#...#...#..",
                    ".#....#..#.",
                    "..#.#...#.#",
                    ".#...##..#.",
                    "..#.##.....",
                    ".#.#.#....#",
                    ".#........#",
                    "#.##...#...",
                    "#...##....#",
                    ".#..#...#.#"
                };

                int singleMoveX           = 3;
                int singleMoveY           = 1;
                var expectedNumberOfTrees = 7;
                var xmasTreeMap           = new XmasTreeMapRepositoryWrapper();
                var sut = new XmasTreeMapService(xmasTreeMap.MapLocationsFromLines(lines.ToArray()));

                var resultNumberOfTrees = sut.CountTrees(singleMoveX, singleMoveY);

                Assert.That(resultNumberOfTrees == expectedNumberOfTrees, $"{resultNumberOfTrees} : {expectedNumberOfTrees}");
            }
            public void Should_CountNumberOfTrees(string line, int yPosition, int expectedCount)
            {
                var sut = new XmasTreeMapRepositoryWrapper();

                var treeMap       = sut.MapLocationsFromLine(line, yPosition);
                var numberOfTrees = treeMap.Count(x => x.Type == PositionType.Tree);

                Assert.That(numberOfTrees == expectedCount);
            }
            public void Should_CreateMap_When_ValidLines()
            {
                var lines           = new string[] { ".#.", "#.#" };
                var sut             = new XmasTreeMapRepositoryWrapper();
                var expectedTreeMap = new List <MapLocation>()
                {
                    new MapLocation {
                        Type = PositionType.Open, XPosition = 0, YPosition = 0
                    },
                    new MapLocation {
                        Type = PositionType.Tree, XPosition = 1, YPosition = 0
                    },
                    new MapLocation {
                        Type = PositionType.Open, XPosition = 2, YPosition = 0
                    },
                    new MapLocation {
                        Type = PositionType.Tree, XPosition = 0, YPosition = 1
                    },
                    new MapLocation {
                        Type = PositionType.Open, XPosition = 1, YPosition = 1
                    },
                    new MapLocation {
                        Type = PositionType.Tree, XPosition = 2, YPosition = 1
                    },
                };

                var resultTreeMap = sut.MapLocationsFromLines(lines).ToList();

                // Line 1
                Assert.That(resultTreeMap.Count() == expectedTreeMap.Count, $"Count: {resultTreeMap.Count()} != {expectedTreeMap.Count}");
                for (var i = 0; i < resultTreeMap.Count; i++)
                {
                    Assert.That(resultTreeMap[i].Type == expectedTreeMap[i].Type, $"Type[{i}]: {resultTreeMap[i].Type} != {expectedTreeMap[i].Type}");
                    Assert.That(resultTreeMap[i].XPosition == expectedTreeMap[i].XPosition, $"XPosition[{i}]: {resultTreeMap[i].XPosition} != {expectedTreeMap[i].XPosition}");
                    Assert.That(resultTreeMap[i].YPosition == expectedTreeMap[i].YPosition, $"YPosition[{i}]: {resultTreeMap[i].YPosition} != {expectedTreeMap[i].YPosition}");
                }
            }
            public void Should_ThrowException_When_LineEmptyCollection()
            {
                var sut = new XmasTreeMapRepositoryWrapper();

                Assert.Throws <ArgumentOutOfRangeException>(() => sut.MapLocationsFromLines(Enumerable.Empty <string>().ToArray()));
            }
            public void Should_ThrowException_When_LinesNullCollection()
            {
                var sut = new XmasTreeMapRepositoryWrapper();

                Assert.Throws <ArgumentNullException>(() => sut.MapLocationsFromLines(null));
            }
            public void Should_ThrowException_When_InvalidCharacterFoundInMapLine(string line)
            {
                var sut = new XmasTreeMapRepositoryWrapper();

                Assert.Throws <ArgumentOutOfRangeException>(() => sut.MapLocationsFromLine(line, 0));
            }