Ejemplo n.º 1
0
        protected static void SetTargetVertex_Test <TGraph>(
            [NotNull] RootedSearchAlgorithmBase <int, TGraph> algorithm)
            where TGraph : IImplicitVertexSet <int>
        {
            int targetVertexChangeCount = 0;

            algorithm.TargetVertexChanged += (sender, args) => ++ targetVertexChangeCount;

            const int vertex1 = 0;

            algorithm.SetTargetVertex(vertex1);
            Assert.AreEqual(1, targetVertexChangeCount);
            algorithm.TryGetTargetVertex(out int target);
            Assert.AreEqual(vertex1, target);

            // Not changed
            algorithm.SetTargetVertex(vertex1);
            Assert.AreEqual(1, targetVertexChangeCount);
            algorithm.TryGetTargetVertex(out target);
            Assert.AreEqual(vertex1, target);

            const int vertex2 = 1;

            algorithm.SetTargetVertex(vertex2);
            Assert.AreEqual(2, targetVertexChangeCount);
            algorithm.TryGetTargetVertex(out target);
            Assert.AreEqual(vertex2, target);

            algorithm.SetTargetVertex(vertex1);
            Assert.AreEqual(3, targetVertexChangeCount);
            algorithm.TryGetTargetVertex(out target);
            Assert.AreEqual(vertex1, target);
        }
Ejemplo n.º 2
0
        protected static void ComputeWithoutRoot_Throws_Test <TGraph>(
            [NotNull] IMutableVertexSet <int> graph,
            [NotNull, InstantHandle] Func <RootedSearchAlgorithmBase <int, TGraph> > createAlgorithm)
            where TGraph : IImplicitVertexSet <int>
        {
            RootedSearchAlgorithmBase <int, TGraph> algorithm = createAlgorithm();

            Assert.Throws <InvalidOperationException>(algorithm.Compute);

            // Source (and target) vertex set but not to a vertex in the graph
            const int vertex1 = 1;

            algorithm = createAlgorithm();
            algorithm.SetRootVertex(vertex1);
            algorithm.SetTargetVertex(vertex1);
            Assert.Throws <VertexNotFoundException>(algorithm.Compute);

            const int vertex2 = 2;

            graph.AddVertex(vertex1);
            algorithm = createAlgorithm();
            algorithm.SetRootVertex(vertex1);
            algorithm.SetTargetVertex(vertex2);
            Assert.Throws <VertexNotFoundException>(algorithm.Compute);
        }
Ejemplo n.º 3
0
        protected static void ClearTargetVertex_Test <TVertex, TGraph>(
            [NotNull] RootedSearchAlgorithmBase <TVertex, TGraph> algorithm)
            where TVertex : new()
            where TGraph : IImplicitVertexSet <TVertex>
        {
            int targetVertexChangeCount = 0;

            // ReSharper disable once AccessToModifiedClosure
            algorithm.TargetVertexChanged += (sender, args) => ++ targetVertexChangeCount;

            algorithm.ClearTargetVertex();
            Assert.AreEqual(0, targetVertexChangeCount);

            var vertex = new TVertex();

            SetTargetVertex(vertex);
            algorithm.ClearTargetVertex();
            Assert.AreEqual(1, targetVertexChangeCount);

            algorithm.ClearTargetVertex();
            Assert.AreEqual(1, targetVertexChangeCount);

            #region Local function

            void SetTargetVertex(TVertex v)
            {
                algorithm.SetTargetVertex(v);
                targetVertexChangeCount = 0;
            }

            #endregion
        }
Ejemplo n.º 4
0
 protected static void SetTargetVertex_Throws_Test <TVertex, TGraph>(
     [NotNull] RootedSearchAlgorithmBase <TVertex, TGraph> algorithm)
     where TVertex : class
     where TGraph : IImplicitVertexSet <TVertex>
 {
     // ReSharper disable once AssignNullToNotNullAttribute
     Assert.Throws <ArgumentNullException>(() => algorithm.SetTargetVertex(null));
 }
Ejemplo n.º 5
0
        protected static void TryGetTargetVertex_Test <TVertex, TGraph>(
            [NotNull] RootedSearchAlgorithmBase <TVertex, TGraph> algorithm)
            where TVertex : new()
            where TGraph : IImplicitVertexSet <TVertex>
        {
            Assert.IsFalse(algorithm.TryGetTargetVertex(out _));

            var vertex = new TVertex();

            algorithm.SetTargetVertex(vertex);
            Assert.IsTrue(algorithm.TryGetTargetVertex(out TVertex target));
            AssertEqual(vertex, target);
        }