public void Test1TwoPoints() { // build test case. var router = new RouterMock(); var locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; var matrixAlgorithm = new WeightMatrixAlgorithm(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), locations, null); // run. matrixAlgorithm.Run(); Assert.IsNotNull(matrixAlgorithm); Assert.IsTrue(matrixAlgorithm.HasRun); Assert.IsTrue(matrixAlgorithm.HasSucceeded); Assert.AreEqual(0, matrixAlgorithm.Errors.Count); var matrix = matrixAlgorithm.Weights; Assert.IsNotNull(matrix); Assert.AreEqual(0, matrix[0][0]); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(locations[0], locations[1]), matrix[0][1], 0.1); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(locations[1], locations[0]), matrix[1][0], 0.1); Assert.AreEqual(0, matrix[1][1]); Assert.AreEqual(2, matrixAlgorithm.RouterPoints.Count); Assert.AreEqual(0, matrixAlgorithm.IndexOf(0)); Assert.AreEqual(1, matrixAlgorithm.IndexOf(1)); }
public void Test1TwoPointsWithMatching() { // build test case. var router = new RouterMock(new AttributeCollection(new Attribute("highway", "residential"))); var locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; var matrixAlgorithm = new WeightMatrixAlgorithm(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), locations, (edge, i) => { return(true); }); // run. matrixAlgorithm.Run(); Assert.IsNotNull(matrixAlgorithm); Assert.IsTrue(matrixAlgorithm.HasRun); Assert.IsTrue(matrixAlgorithm.HasSucceeded); Assert.AreEqual(0, matrixAlgorithm.Errors.Count); var matrix = matrixAlgorithm.Weights; Assert.IsNotNull(matrix); Assert.AreEqual(0, matrix[0][0]); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(locations[0], locations[1]), matrix[0][1], 0.1); Assert.AreEqual(Coordinate.DistanceEstimateInMeter(locations[1], locations[0]), matrix[1][0], 0.1); Assert.AreEqual(0, matrix[1][1]); Assert.AreEqual(2, matrixAlgorithm.RouterPoints.Count); Assert.AreEqual(0, matrixAlgorithm.IndexOf(0)); Assert.AreEqual(1, matrixAlgorithm.IndexOf(1)); // build test case. router = new RouterMock(new AttributeCollection(new Attribute("highway", "primary"))); locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; matrixAlgorithm = new WeightMatrixAlgorithm(router, Vehicle.Car.Fastest(), locations, (edge, i) => { return(false); }); // run. matrixAlgorithm.Run(); Assert.IsNotNull(matrixAlgorithm); Assert.IsTrue(matrixAlgorithm.HasRun); Assert.IsTrue(matrixAlgorithm.HasSucceeded); Assert.AreEqual(2, matrixAlgorithm.Errors.Count); Assert.AreEqual(LocationErrorCode.NotResolved, matrixAlgorithm.Errors[0].Code); Assert.AreEqual(LocationErrorCode.NotResolved, matrixAlgorithm.Errors[1].Code); }
public void Test3TwoPoints() { // build test case. var invalidSet = new HashSet <int>(); invalidSet.Add(1); var router = new RouterMock(invalidSet); var locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; var matrixAlgorithm = new WeightMatrixAlgorithm(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), locations, null); // run. matrixAlgorithm.Run(); Assert.IsNotNull(matrixAlgorithm); Assert.IsTrue(matrixAlgorithm.HasRun); Assert.IsTrue(matrixAlgorithm.HasSucceeded); Assert.AreEqual(1, matrixAlgorithm.Errors.Count); Assert.IsTrue(matrixAlgorithm.Errors.ContainsKey(1)); var matrix = matrixAlgorithm.Weights; Assert.IsNotNull(matrix); Assert.AreEqual(0, matrix[0][0]); Assert.AreEqual(1, matrixAlgorithm.RouterPoints.Count); Assert.AreEqual(0, matrixAlgorithm.IndexOf(0)); Assert.AreEqual(0, matrixAlgorithm.LocationIndexOf(0)); // build test case. invalidSet.Clear(); invalidSet.Add(0); router = new RouterMock(invalidSet); locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; matrixAlgorithm = new WeightMatrixAlgorithm(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), locations, null); // run. matrixAlgorithm.Run(); Assert.IsNotNull(matrixAlgorithm); Assert.IsTrue(matrixAlgorithm.HasRun); Assert.IsTrue(matrixAlgorithm.HasSucceeded); Assert.AreEqual(1, matrixAlgorithm.Errors.Count); Assert.IsTrue(matrixAlgorithm.Errors.ContainsKey(0)); matrix = matrixAlgorithm.Weights; Assert.IsNotNull(matrix); Assert.AreEqual(0, matrix[0][0]); Assert.AreEqual(1, matrixAlgorithm.RouterPoints.Count); Assert.AreEqual(0, matrixAlgorithm.IndexOf(1)); Assert.AreEqual(1, matrixAlgorithm.LocationIndexOf(0)); }