public void TourMustNotContainInvalidNodeIndicesAfterInitialisation() { // arrange var data = ProblemData(); var roulette = Substitute.For<INodeSelector>(); var ant = new Ant(0, data, roulette); // act ant.Initialise(2); // assert Assert.IsFalse(ant.Tour.Any(n => n == -1)); }
public void TourLengthShouldBeZeroAfterInitialisation() { // arrange const int startNode = 4; var data = ProblemData(); var roulette = Substitute.For<INodeSelector>(); var ant = new Ant(0, data, roulette); // act ant.Initialise(startNode); // assert Assert.AreEqual(0.0, ant.TourLength); }
public void CurrentNodeShouldReturnCorrectIndex() { // arrange const int currentNode = 3; var data = ProblemData(); var roulette = Substitute.For<INodeSelector>(); var ant = new Ant(0, data, roulette); roulette.SelectNextNode(ant).Returns(currentNode); // act ant.Initialise(7); ant.Step(1); // assert Assert.AreEqual(currentNode, ant.CurrentNode); }
public void StepShouldBuildCorrectTourLength() { // arrange var expectedTour = new[] { 7, 3, 8, 2, 7 }; var roulette = Substitute.For<INodeSelector>(); var data = ProblemData(); var ant = new Ant(0, data, roulette); // act ant.Initialise(7); for (var i = 1; i < expectedTour.Length; i++) { roulette.SelectNextNode(ant).Returns(expectedTour[i]); ant.Step(i); } // assert Assert.AreEqual(8, ant.TourLength); Assert.AreEqual(expectedTour, ant.Tour); }
public void TourShouldHaveOnlyStartNodeAfterInitialisation() { // arrange const int startNode = 2; var data = ProblemData(); var roulette = Substitute.For<INodeSelector>(); var ant = new Ant(0, data, roulette); // act ant.Initialise(startNode); // assert Assert.AreEqual(new[] { startNode }, ant.Tour); }
public void VisitedShouldReturnCorrectFlagsForAllAllNodes() { var visited = new[] { false, false, false, true, false, false, false, true, true, false }; var tourSoFar = new[] { 7, 3, 8 }; var roulette = Substitute.For<INodeSelector>(); var data = ProblemData(); var ant = new Ant(0, data, roulette); // act ant.Initialise(7); for (var i = 1; i < tourSoFar.Length; i++) { roulette.SelectNextNode(ant).Returns(tourSoFar[i]); ant.Step(i); } Assert.AreEqual(visited, ant.Visited); }