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"); }
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."); }
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"); }
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); }
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); }
public void IsNearThrowTest() { var source = new CoordinateInt2D() { X = 1, Y = 1 }; Action isNearAction = () => { source.IsNear(null); }; isNearAction.Should().Throw <ArgumentNullException>(); }
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); }
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(); }
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(); }
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)"); }
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); }
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(); }
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); }
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); }
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); }