Beispiel #1
0
        public void SubScheduleWithLinkBackToParent()
        {
            var id = new ScheduleId();

            var       subScheduleId = new ScheduleId();
            ISchedule subSchedule;
            {
                var subGraph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start    = new StartVertex(1);
                var end      = new EndVertex(2);
                var vertex1  = new SubScheduleVertex(3, id);
                subGraph.AddVertex(start);
                subGraph.AddVertex(end);
                subGraph.AddVertex(vertex1);
                subGraph.AddEdge(new ScheduleEdge(start, vertex1));
                subGraph.AddEdge(new ScheduleEdge(vertex1, end));
                subSchedule = new Schedule(subGraph, start, end);
            }

            IScheduleVertex errorVertex;
            Schedule        schedule;
            {
                var graph   = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start   = new StartVertex(1);
                var end     = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, subScheduleId);
                graph.AddVertex(start);
                graph.AddVertex(end);
                graph.AddVertex(vertex1);
                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, end));
                schedule = new Schedule(graph, start, end);

                errorVertex = vertex1;
            }

            var knownSchedules = new Mock <IStoreSchedules>();
            {
                knownSchedules.Setup(s => s.Contains(It.IsAny <ScheduleId>()))
                .Returns <ScheduleId>(subScheduleId.Equals);
                knownSchedules.Setup(s => s.Schedule(It.IsAny <ScheduleId>()))
                .Returns <ScheduleId>(scheduleId => subSchedule);
            }

            var failures = new List <Tuple <ScheduleIntegrityFailureType, IScheduleVertex> >();

            var verifier = new ScheduleVerifier(knownSchedules.Object);
            var result   = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple <ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.SubScheduleLinksBackToParentSchedule, failures[0].Item1);
            Assert.AreSame(errorVertex, failures[0].Item2);
        }
Beispiel #2
0
        public void CycleWithNoEdgesFromStart()
        {
            var knownSchedules = new Mock <IStoreSchedules>();
            var verifier       = new ScheduleVerifier(knownSchedules.Object);

            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, end));
            graph.AddEdge(new ScheduleEdge(vertex1, end));
            graph.AddEdge(new ScheduleEdge(vertex1, vertex2));
            graph.AddEdge(new ScheduleEdge(vertex2, vertex3));
            graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

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

            var id       = new ScheduleId();
            var failures = new List <Tuple <ScheduleIntegrityFailureType, IScheduleVertex> >();
            var result   = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple <ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(3, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleVertexIsNotReachableFromStart, failures[0].Item1);
            Assert.AreSame(vertex1, failures[0].Item2);

            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleVertexIsNotReachableFromStart, failures[1].Item1);
            Assert.AreSame(vertex2, failures[1].Item2);

            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleVertexIsNotReachableFromStart, failures[2].Item1);
            Assert.AreSame(vertex3, failures[2].Item2);
        }
        public void CycleWithNoEdgesToEnd()
        {
            var knownSchedules = new Mock<IStoreSchedules>();
            var verifier = new ScheduleVerifier(knownSchedules.Object);

            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, end));
            graph.AddEdge(new ScheduleEdge(start, vertex1));
            graph.AddEdge(new ScheduleEdge(vertex1, vertex2));
            graph.AddEdge(new ScheduleEdge(vertex2, vertex3));
            graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

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

            var id = new ScheduleId();
            var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>();
            var result = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(3, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleEndIsNotReachableFromVertex, failures[0].Item1);
            Assert.AreSame(vertex1, failures[0].Item2);

            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleEndIsNotReachableFromVertex, failures[1].Item1);
            Assert.AreSame(vertex2, failures[1].Item2);

            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleEndIsNotReachableFromVertex, failures[2].Item1);
            Assert.AreSame(vertex3, failures[2].Item2);
        }
Beispiel #4
0
        public void EndVertexWithOutboundEdges()
        {
            var knownSchedules = new Mock <IStoreSchedules>();
            var verifier       = new ScheduleVerifier(knownSchedules.Object);

            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));
                graph.AddEdge(new ScheduleEdge(end, vertex1));

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

            var id       = new ScheduleId();
            var failures = new List <Tuple <ScheduleIntegrityFailureType, IScheduleVertex> >();
            var result   = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple <ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleIsMissingEnd, failures[0].Item1);
            Assert.AreSame(schedule.End, failures[0].Item2);
        }
Beispiel #5
0
        public void VertexWithMultipleEdgesInOneDirection()
        {
            var knownSchedules = new Mock <IStoreSchedules>();
            var verifier       = new ScheduleVerifier(knownSchedules.Object);

            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);

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

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

            var id       = new ScheduleId();
            var failures = new List <Tuple <ScheduleIntegrityFailureType, IScheduleVertex> >();
            var result   = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple <ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.VertexLinksToOtherVertexInMultipleWays, failures[0].Item1);
            Assert.AreSame(vertex1, failures[0].Item2);
        }
        public void VertexWithMultipleEdgesInOneDirection()
        {
            var knownSchedules = new Mock<IStoreSchedules>();
            var verifier = new ScheduleVerifier(knownSchedules.Object);

            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);

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

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

            var id = new ScheduleId();
            var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>();
            var result = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.VertexLinksToOtherVertexInMultipleWays, failures[0].Item1);
            Assert.AreSame(vertex1, failures[0].Item2);
        }
        public void SubScheduleWithLinkBackToParent()
        {
            var id = new ScheduleId();

            var subScheduleId = new ScheduleId();
            ISchedule subSchedule;
            {
                var subGraph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                var end = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, id);
                subGraph.AddVertex(start);
                subGraph.AddVertex(end);
                subGraph.AddVertex(vertex1);
                subGraph.AddEdge(new ScheduleEdge(start, vertex1));
                subGraph.AddEdge(new ScheduleEdge(vertex1, end));
                subSchedule = new Schedule(subGraph, start, end);
            }

            IScheduleVertex errorVertex;
            Schedule schedule;
            {
                var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                var end = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, subScheduleId);
                graph.AddVertex(start);
                graph.AddVertex(end);
                graph.AddVertex(vertex1);
                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, end));
                schedule = new Schedule(graph, start, end);

                errorVertex = vertex1;
            }

            var knownSchedules = new Mock<IStoreSchedules>();
            {
                knownSchedules.Setup(s => s.Contains(It.IsAny<ScheduleId>()))
                    .Returns<ScheduleId>(subScheduleId.Equals);
                knownSchedules.Setup(s => s.Schedule(It.IsAny<ScheduleId>()))
                    .Returns<ScheduleId>(scheduleId => subSchedule);
            }

            var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>();

            var verifier = new ScheduleVerifier(knownSchedules.Object);
            var result = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.SubScheduleLinksBackToParentSchedule, failures[0].Item1);
            Assert.AreSame(errorVertex, failures[0].Item2);
        }
        public void StartVertexWithInboundEdges()
        {
            var knownSchedules = new Mock<IStoreSchedules>();
            var verifier = new ScheduleVerifier(knownSchedules.Object);

            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, start));
                graph.AddEdge(new ScheduleEdge(vertex2, end));

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

            var id = new ScheduleId();
            var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>();
            var result = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.ScheduleIsMissingStart, failures[0].Item1);
            Assert.AreSame(schedule.Start, failures[0].Item2);
        }