Exemplo n.º 1
0
        public void TestCalculateManhattanDistance(string moves, int expectedDistance)
        {
            Point start          = new Point(0, 0);
            var   sut            = new PointCalculator(start, moves);
            var   lastPoint      = sut.Calculate().Last();
            int   actualDistance = ManhattanDistance.Calculate(start, lastPoint);

            Assert.Equal(expectedDistance, actualDistance);
        }
Exemplo n.º 2
0
        public void TestCalculateResultOfFirstPuzzle(string firstMoves, string secondMoves, int expectedDistance)
        {
            Point start             = new Point(0, 0);
            var   sut               = new PointCalculator(start, firstMoves);
            var   pointOfFirstMoves = sut.Calculate();

            sut = new PointCalculator(start, secondMoves);
            var pointOfSecondMoves = sut.Calculate();

            var minDistanceOfIntersectingPoints = pointOfFirstMoves.Intersect(pointOfSecondMoves)
                                                  .Select(p => ManhattanDistance.Calculate(start, p))
                                                  .Min();

            Assert.Equal(expectedDistance, minDistanceOfIntersectingPoints);
        }
Exemplo n.º 3
0
        public void TestCalculateResultOfSecondPuzzle(string firstMoves, string secondMoves, int expectedSteps)
        {
            Point start             = new Point(0, 0);
            var   sut               = new PointCalculator(start, firstMoves);
            var   pointOfFirstMoves = sut.Calculate();

            sut = new PointCalculator(start, secondMoves);
            var pointOfSecondMoves = sut.Calculate();

            var        intersectingPoints = pointOfFirstMoves.Intersect(pointOfSecondMoves);
            List <int> steps = new List <int>();

            foreach (var point in intersectingPoints)
            {
                var firstSteps  = pointOfFirstMoves.Where(p => p.Equals(point)).Select(p => p.Count);
                var secondSteps = pointOfSecondMoves.Where(p => p.Equals(point)).Select(p => p.Count);
                steps.Add(firstSteps.First() + secondSteps.First());
            }
            var actualBestSteps = steps.Min();

            Assert.Equal(expectedSteps, actualBestSteps);
        }