예제 #1
0
        public void TestDestinationEqualSource()
        {
            var source = new CoordinateInt2D()
            {
                X = 1,
                Y = 1
            };
            var drone = new Drone(source)
            {
                Name        = "someDrone",
                StorageSize = 10,
                Speed       = 1
            };
            var playerCtx = new PlayerContext()
            {
                Level = 1
            };

            var dateStart = new DateTime(2018, 1, 1, 0, 0, 0);

            Action action = () =>
            {
                var move = new MoveTo(playerCtx, drone, dateStart, source, source);
            };

            action.Should().Throw <InvalidInstructionException>()
            .WithMessage("The drone is already at destination");
        }
예제 #2
0
        public void TestMoveOutsideOfTheMap()
        {
            var source = new CoordinateInt2D()
            {
                X = 10,
                Y = 10
            };
            var dest = new CoordinateInt2D()
            {
                X = -1,
                Y = -1
            };
            var drone = new Drone(source)
            {
                Name        = "someDrone",
                StorageSize = 10,
                Speed       = 1
            };
            var playerCtx = new PlayerContext()
            {
                Level = 1
            };

            var dateStart = new DateTime(2018, 1, 1, 0, 0, 0);

            Action action = () =>
            {
                var move = new MoveTo(playerCtx, drone, dateStart, source, dest);
            };

            action.Should().Throw <InvalidInstructionException>()
            .WithMessage("Destination is outside of the map.");
        }
예제 #3
0
        public void TestNoMainBuilding()
        {
            var source = new CoordinateInt2D()
            {
                X = 10,
                Y = 10
            };
            var drone = new Drone(source)
            {
                Name        = "someDrone",
                StorageSize = 10,
                Speed       = 1
            };
            var playerCtx = new PlayerContext()
            {
                Level = 1
            };

            var dateStart = new DateTime(2018, 1, 1, 0, 0, 0);

            Action action = () =>
            {
                new Unload(playerCtx, drone, dateStart);
            };

            action.Should().Throw <InvalidInstructionException>()
            .WithMessage("No factory near the drone");
        }
예제 #4
0
        public void ForceInsideOut2Test()
        {
            var coord = new CoordinateInt2D()
            {
                X = 1,
                Y = 1
            };

            var area = new Tuple <CoordinateInt2D, CoordinateInt2D>(
                new CoordinateInt2D()
            {
                X = 5,
                Y = 5
            }, new CoordinateInt2D()
            {
                X = 10,
                Y = 10
            }
                );

            var expected = new CoordinateInt2D()
            {
                X = 5,
                Y = 5
            };

            var inside = coord.ForceInside(area);

            inside.Should().BeEquivalentTo(expected);
        }
예제 #5
0
        public void TestMoveToInstruction()
        {
            var drone = CreateDrone();

            var date = new DateTime(2018, 1, 1);
            var dest = new CoordinateInt2D()
            {
                X = 45, Y = 45
            };
            var source = new CoordinateInt2D()
            {
                X = 1, Y = 1
            };

            var globalInstruction = new GlobalInstruction()
            {
                TYPE        = "MoveTo",
                Destination = dest,
                DroneName   = "Drone_1"
            };
            var playerCtx = new PlayerContext()
            {
                Level = 1
            };


            var mapper = new InstructionMapper(playerCtx);
            var expectedInstruction = new MoveTo(playerCtx, drone, date, source, dest);


            var actualInstruction = mapper.ToSpecificInstruction(globalInstruction, drone, date);

            actualInstruction.Should().BeEquivalentTo(expectedInstruction);
        }
예제 #6
0
        public void IsNearThrowTest()
        {
            var source = new CoordinateInt2D()
            {
                X = 1,
                Y = 1
            };

            Action isNearAction = () =>
            {
                source.IsNear(null);
            };

            isNearAction.Should().Throw <ArgumentNullException>();
        }
예제 #7
0
        public void GetDistanceToTest()
        {
            var source = new CoordinateInt2D()
            {
                X = 0,
                Y = 0
            };

            var dest = new CoordinateInt2D()
            {
                X = 3,
                Y = 4
            };
            var distance = source.GetDistanceTo(dest);

            distance.Should().Be(5);
        }
예제 #8
0
        public void IsGoalAchievedFail2Ressources()
        {
            var initPos = new CoordinateInt2D()
            {
                X = 4, Y = 4
            };
            var rq = new ResourceQuantity()
            {
                Resource = ResourceType.Gold, Quantity = 10
            };
            var goal = new List <ResourceQuantity>()
            {
                new ResourceQuantity()
                {
                    Resource = ResourceType.Gold, Quantity = 10
                },
                new ResourceQuantity()
                {
                    Resource = ResourceType.Silver, Quantity = 10
                }
            };
            var cntx = new PlayerContext()
            {
                Level = 1
            };
            var mockedDrone = new Mock <IDrone>();

            mockedDrone
            .Setup(dr => dr.GetValidInstructions())
            .Returns(new List <IInstruction>()
            {
                new Unload(cntx, new Drone(initPos), new DateTime(2018, 1, 1, 0, 0, 0))
                {
                    Resource = rq
                }
            });

            cntx.Drones = new List <IDrone>()
            {
                mockedDrone.Object
            };

            cntx.IsResourceGoalAchieved(goal).Should().BeFalse();
        }
예제 #9
0
        public void IsNearTest()
        {
            var source = new CoordinateInt2D()
            {
                X = 1,
                Y = 1
            };

            var dest = new CoordinateInt2D()
            {
                X = 3,
                Y = 4
            };
            var near = source.IsNear(source);

            near.Should().BeTrue();
            near = source.IsNear(dest);
            near.Should().BeFalse();
        }
예제 #10
0
        public void PathProgressionWrongProgressionTest()
        {
            var origin = new CoordinateInt2D()
            {
                X = 6,
                Y = 3
            };
            var destination = new CoordinateInt2D()
            {
                X = 0,
                Y = 0
            };

            Action pathProgressionAction = () =>
            {
                origin.PathProgression(destination, 2);
            };

            pathProgressionAction.Should().Throw <Exception>()
            .WithMessage("progression must be a percentage between 0 and 1 (including)");
        }
예제 #11
0
        public void GetStoredResourcesAtTest()
        {
            var initPos = new CoordinateInt2D()
            {
                X = 4, Y = 4
            };
            var rq = new ResourceQuantity()
            {
                Resource = ResourceType.Gold, Quantity = 42
            };
            var cntx = new PlayerContext()
            {
                Level = 1
            };
            var mockedDrone = new Mock <IDrone>();

            mockedDrone
            .Setup(dr => dr.GetValidInstructions())
            .Returns(new List <IInstruction>()
            {
                new Unload(cntx, new Drone(initPos), new DateTime(2018, 1, 1, 0, 0, 0))
                {
                    Resource = rq
                }
            });

            cntx.Drones = new List <IDrone>()
            {
                mockedDrone.Object
            };
            IEnumerable <ResourceQuantity> expected = new List <ResourceQuantity>()
            {
                rq
            };

            var actual = cntx.Resources;

            actual.Should().BeEquivalentTo(expected);
        }
예제 #12
0
        public void IsInsideFalseTest()
        {
            var coord = new CoordinateInt2D()
            {
                X = 15,
                Y = 15
            };

            var area = new Tuple <CoordinateInt2D, CoordinateInt2D>(
                new CoordinateInt2D()
            {
                X = 0,
                Y = 0
            }, new CoordinateInt2D()
            {
                X = 10,
                Y = 10
            }
                );
            var inside = coord.IsInside(area);

            inside.Should().BeFalse();
        }
예제 #13
0
        public void PathProgressionNegativeTest()
        {
            var origin = new CoordinateInt2D()
            {
                X = 6,
                Y = 3
            };
            var destination = new CoordinateInt2D()
            {
                X = 0,
                Y = 0
            };

            var expected = new CoordinateInt2D()
            {
                X = 2,
                Y = 1
            };

            var actual = origin.PathProgression(destination, 0.6666666);

            actual.Should().BeEquivalentTo(expected);
        }
예제 #14
0
        public void PathProgressionTest()
        {
            var origin = new CoordinateInt2D()
            {
                X = 0,
                Y = 0
            };
            var destination = new CoordinateInt2D()
            {
                X = 10,
                Y = 10
            };

            var expected = new CoordinateInt2D()
            {
                X = 5,
                Y = 5
            };

            var actual = origin.PathProgression(destination, 0.5);

            actual.Should().BeEquivalentTo(expected);
        }
예제 #15
0
        public void TestGetStateAt()
        {
            var source = new CoordinateInt2D()
            {
                X = 1,
                Y = 1
            };
            var dest = new CoordinateInt2D()
            {
                X = 1,
                Y = 10
            };
            var drone = new Drone(source)
            {
                Name        = "someDrone",
                StorageSize = 10,
                Speed       = 1
            };
            var playerCtx = new PlayerContext()
            {
                Level = 1
            };
            var dateStart = new DateTime(2018, 1, 1, 0, 0, 0);
            var date      = new DateTime(2018, 1, 1, 0, 0, 4);
            var moveTo    = new MoveTo(playerCtx, drone, dateStart, source, dest);

            var actual = moveTo.GetPositionAt(date);

            var expected = new CoordinateInt2D()
            {
                X = 1,
                Y = 5
            };

            actual.Should().BeEquivalentTo(expected);
        }