Пример #1
0
        public void TraverseScheduleWithLoop()
        {
            // Making a schedule that looks like:
            // start -> node1 --> node2 -> end
            //            ^           |
            //            |-- node3 <-|
            Schedule schedule;
            {
                var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();

                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new InsertVertex(3);
                graph.AddVertex(vertex1);

                var vertex2 = new InsertVertex(4);
                graph.AddVertex(vertex2);

                var vertex3 = new InsertVertex(5);
                graph.AddVertex(vertex3);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));

                graph.AddEdge(new ScheduleEdge(vertex2, end));
                graph.AddEdge(new ScheduleEdge(vertex2, vertex3));

                graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

                schedule = new Schedule(graph, start, end);
            }

            var vertices = new List <int>();

            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
            {
                vertices.Add(vertex.Index);
                return(true);
            });

            Assert.That(vertices, Is.EquivalentTo(new[] { 1, 3, 4, 2, 5 }));
        }
Пример #2
0
        public void TraverseScheduleCompletely()
        {
            Schedule schedule;
            {
                var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();

                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new InsertVertex(3);
                graph.AddVertex(vertex1);

                var vertex2 = new InsertVertex(4);
                graph.AddVertex(vertex2);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));
                graph.AddEdge(new ScheduleEdge(vertex2, end));

                schedule = new Schedule(graph, start, end);
            }

            var vertices = new List <int>();

            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
            {
                vertices.Add(vertex.Index);
                return(true);
            });

            Assert.That(vertices, Is.EquivalentTo(new[] { 1, 3, 4, 2 }));
        }
Пример #3
0
        public void TraverseScheduleWithLoop()
        {
            // Making a schedule that looks like:
            // start -> node1 --> node2 -> end
            //            ^           |
            //            |-- node3 <-|
            Schedule schedule;
            {
                var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();

                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new InsertVertex(3);
                graph.AddVertex(vertex1);

                var vertex2 = new InsertVertex(4);
                graph.AddVertex(vertex2);

                var vertex3 = new InsertVertex(5);
                graph.AddVertex(vertex3);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));

                graph.AddEdge(new ScheduleEdge(vertex2, end));
                graph.AddEdge(new ScheduleEdge(vertex2, vertex3));

                graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

                schedule = new Schedule(graph, start, end);
            }

            var vertices = new List<int>();
            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
                {
                    vertices.Add(vertex.Index);
                    return true;
                });

            Assert.That(vertices, Is.EquivalentTo(new[] { 1, 3, 4, 2, 5 }));
        }
Пример #4
0
        public void TraverseSchedulePartially()
        {
            Schedule schedule;
            {
                var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();

                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new InsertVertex(3);
                graph.AddVertex(vertex1);

                var vertex2 = new InsertVertex(4);
                graph.AddVertex(vertex2);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));
                graph.AddEdge(new ScheduleEdge(vertex2, end));

                schedule = new Schedule(graph, start, end);
            }

            var vertices = new List<int>();
            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
                {
                    vertices.Add(vertex.Index);
                    return vertex.Index != 3;
                });

            Assert.That(vertices, Is.EquivalentTo(new[] { 1, 3 }));
        }