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 <float>(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), new Itinero.Algorithms.Search.MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Vehicle.Car.Fastest() }, 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.CorrectedIndexOf(0)); Assert.AreEqual(1, matrixAlgorithm.CorrectedIndexOf(1)); }
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 <float>(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), new Itinero.Algorithms.Search.MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Vehicle.Car.Fastest() }, 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.CorrectedIndexOf(0)); Assert.AreEqual(0, matrixAlgorithm.OriginalIndexOf(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 <float>(router, Vehicle.Car.Fastest(), new DefaultWeightHandlerMock(), new Itinero.Algorithms.Search.MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Vehicle.Car.Fastest() }, 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.CorrectedIndexOf(1)); Assert.AreEqual(1, matrixAlgorithm.OriginalIndexOf(0)); }
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 Test1TwoPointsWithMatching() { // build test case. var router = new RouterMock(new AttributeCollection(new Itinero.Attributes.Attribute("highway", "residential"))); var locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; var resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations, (edge, i) => { return(true); }); // run. resolver.Run(); // check result. Assert.IsNotNull(resolver); Assert.IsTrue(resolver.HasRun); Assert.IsTrue(resolver.HasSucceeded); Assert.AreEqual(0, resolver.Errors.Count); Assert.AreEqual(2, resolver.RouterPoints.Count); Assert.AreEqual(0, resolver.ResolvedIndexOf(0)); Assert.AreEqual(1, resolver.ResolvedIndexOf(1)); // build test case. router = new RouterMock(new AttributeCollection(new Itinero.Attributes.Attribute("highway", "primary"))); locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }; resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations, (edge, i) => { return(false); }); // run. resolver.Run(); Assert.IsNotNull(resolver); Assert.IsTrue(resolver.HasRun); Assert.IsTrue(resolver.HasSucceeded); Assert.AreEqual(2, resolver.Errors.Count); Assert.AreEqual(LocationErrorCode.NotResolved, resolver.Errors[0].Code); Assert.AreEqual(LocationErrorCode.NotResolved, resolver.Errors[1].Code); }
public void Test2TwoPoints() { // build test case. var router = new RouterMock(); var locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(180, 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. locations = new Coordinate[] { new Coordinate(180, 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)); }
public void Test2TwoPoints() { // build test case. var router = new RouterMock(); var locations = new Coordinate[] { new Coordinate(0, 0), new Coordinate(180, 1) }; var resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations); // run. resolver.Run(); Assert.IsNotNull(resolver); Assert.IsTrue(resolver.HasRun); Assert.IsTrue(resolver.HasSucceeded); Assert.AreEqual(1, resolver.Errors.Count); Assert.IsTrue(resolver.Errors.ContainsKey(1)); Assert.AreEqual(1, resolver.RouterPoints.Count); Assert.AreEqual(0, resolver.ResolvedIndexOf(0)); Assert.AreEqual(0, resolver.LocationIndexOf(0)); // build test case. locations = new Coordinate[] { new Coordinate(180, 0), new Coordinate(1, 1) }; resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations); // run. resolver.Run(); Assert.IsNotNull(resolver); Assert.IsTrue(resolver.HasRun); Assert.IsTrue(resolver.HasSucceeded); Assert.AreEqual(1, resolver.Errors.Count); Assert.IsTrue(resolver.Errors.ContainsKey(0)); Assert.AreEqual(0, resolver.ResolvedIndexOf(1)); Assert.AreEqual(1, resolver.LocationIndexOf(0)); }