Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }