Пример #1
0
        public void TestOverwritingInstructions()
        {
            var route = new Route()
            {
                Shape = new Coordinate[]
                {
                    new Coordinate(0, 0),
                    new Coordinate(0, 0),
                    new Coordinate(0, 0)
                },
                ShapeMeta = new Route.Meta[]
                {
                    new Route.Meta()
                    {
                        Shape = 0
                    },
                    new Route.Meta()
                    {
                        Shape = 1
                    },
                    new Route.Meta()
                    {
                        Shape = 2
                    }
                },
                TotalDistance = 0,
                TotalTime     = 0
            };

            var generator = new UnimodalInstructionGenerator(route,
                                                             new UnimodalInstructionGenerator.TryGetDelegate[]
            {
                (RoutePosition pos, ILanguageReference langRef, out Instruction instruction) =>
                {
                    if (pos.Shape == 2)
                    {
                        instruction = new Instruction()
                        {
                            Text  = "The one and only instruction!",
                            Shape = pos.Shape
                        };
                        return(3);
                    }
                    instruction = instruction = new Instruction()
                    {
                        Text  = string.Format("Instruction {0}", pos.Shape),
                        Shape = pos.Shape
                    };
                    return(1);
                }
            }, new MockLanguageReference());

            generator.Run();

            var instructions = generator.Instructions;

            Assert.IsNotNull(instructions);
            Assert.AreEqual(1, instructions.Count);
            Assert.AreEqual("The one and only instruction!", instructions[0].Text);
        }
Пример #2
0
        public void TestMergeInstructions()
        {
            var route = new Route()
            {
                Shape = new Coordinate[]
                {
                    new Coordinate(0, 0),
                    new Coordinate(0, 0),
                    new Coordinate(0, 0)
                },
                ShapeMeta = new Route.Meta[]
                {
                    new Route.Meta()
                    {
                        Shape = 0
                    },
                    new Route.Meta()
                    {
                        Shape = 1
                    },
                    new Route.Meta()
                    {
                        Shape = 2
                    }
                },
                TotalDistance = 0,
                TotalTime     = 0
            };

            var generator = new UnimodalInstructionGenerator(route,
                                                             new UnimodalInstructionGenerator.TryGetDelegate[]
            {
                (RoutePosition pos, ILanguageReference langRef, out Instruction instruction) =>
                {
                    instruction = new Instruction()
                    {
                        Text  = string.Format("Instruction {0}", pos.Shape),
                        Shape = pos.Shape
                    };
                    return(1);
                }
            },
                                                             (Route r, ILanguageReference langRef, Instruction i1, Instruction i2, out Instruction i) =>
            {
                i = new Instruction()
                {
                    Text = string.Format("Merged instruction: {0} -> {1}", i1.Text, i2.Text)
                };
                return(true);
            }, new MockLanguageReference());

            generator.Run();

            var instructions = generator.Instructions;

            Assert.IsNotNull(instructions);
            Assert.AreEqual(1, instructions.Count);
            Assert.AreEqual("Merged instruction: Merged instruction: Instruction 0 -> Instruction 1 -> Instruction 2",
                            instructions[0].Text);
        }
Пример #3
0
        public void TestGenerateInstruction()
        {
            var route = new Route()
            {
                Shape = new Coordinate[]
                {
                    new Coordinate(0, 0),
                    new Coordinate(0, 0),
                    new Coordinate(0, 0)
                },
                ShapeMeta = new Route.Meta[]
                {
                    new Route.Meta()
                    {
                        Shape = 0
                    },
                    new Route.Meta()
                    {
                        Shape = 1
                    },
                    new Route.Meta()
                    {
                        Shape = 2
                    }
                },
                TotalDistance = 0,
                TotalTime     = 0
            };

            var generator = new UnimodalInstructionGenerator(route,
                                                             new UnimodalInstructionGenerator.TryGetDelegate[]
            {
                (RoutePosition pos, ILanguageReference langRef, out Instruction instruction) =>
                {
                    instruction = new Instruction()
                    {
                        Shape = pos.Shape,
                        Text  = string.Format("Instruction {0}", pos.Shape)
                    };
                    return(1);
                }
            }, new MockLanguageReference());

            generator.Run();

            var instructions = generator.Instructions;

            Assert.IsNotNull(instructions);
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual(string.Format("Instruction {0}", 0), instructions[0].Text);
            Assert.AreEqual(string.Format("Instruction {0}", 1), instructions[1].Text);
            Assert.AreEqual(string.Format("Instruction {0}", 2), instructions[2].Text);
        }