コード例 #1
0
        protected static void SetRootVertex_Test <TGraph>(
            [NotNull] RootedAlgorithmBase <int, TGraph> algorithm)
            where TGraph : IImplicitVertexSet <int>
        {
            int rootVertexChangeCount = 0;

            algorithm.RootVertexChanged += (_, _) => ++ rootVertexChangeCount;

            const int vertex1 = 0;

            algorithm.SetRootVertex(vertex1);
            Assert.AreEqual(1, rootVertexChangeCount);
            algorithm.TryGetRootVertex(out int root);
            Assert.AreEqual(vertex1, root);

            // Not changed
            algorithm.SetRootVertex(vertex1);
            Assert.AreEqual(1, rootVertexChangeCount);
            algorithm.TryGetRootVertex(out root);
            Assert.AreEqual(vertex1, root);

            const int vertex2 = 1;

            algorithm.SetRootVertex(vertex2);
            Assert.AreEqual(2, rootVertexChangeCount);
            algorithm.TryGetRootVertex(out root);
            Assert.AreEqual(vertex2, root);

            algorithm.SetRootVertex(vertex1);
            Assert.AreEqual(3, rootVertexChangeCount);
            algorithm.TryGetRootVertex(out root);
            Assert.AreEqual(vertex1, root);
        }
コード例 #2
0
        protected static void ClearRootVertex_Test <TVertex, TGraph>(
            [NotNull] RootedAlgorithmBase <TVertex, TGraph> algorithm)
            where TVertex : new()
            where TGraph : IImplicitVertexSet <TVertex>
        {
            int rootVertexChangeCount = 0;

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

            algorithm.ClearRootVertex();
            Assert.AreEqual(0, rootVertexChangeCount);

            var vertex = new TVertex();

            SetRootVertex(vertex);
            algorithm.ClearRootVertex();
            Assert.AreEqual(1, rootVertexChangeCount);

            algorithm.ClearRootVertex();
            Assert.AreEqual(1, rootVertexChangeCount);

            #region Local function

            void SetRootVertex(TVertex v)
            {
                algorithm.SetRootVertex(v);
                rootVertexChangeCount = 0;
            }

            #endregion
        }
コード例 #3
0
 protected static void SetRootVertex_Throws_Test <TVertex, TGraph>(
     [NotNull] RootedAlgorithmBase <TVertex, TGraph> algorithm)
     where TVertex : class
     where TGraph : IImplicitVertexSet <TVertex>
 {
     // ReSharper disable once AssignNullToNotNullAttribute
     Assert.Throws <ArgumentNullException>(() => algorithm.SetRootVertex(null));
 }
コード例 #4
0
        protected static void TryGetRootVertex_Test <TVertex, TGraph>(
            [NotNull] RootedAlgorithmBase <TVertex, TGraph> algorithm)
            where TVertex : new()
            where TGraph : IImplicitVertexSet <TVertex>
        {
            Assert.IsFalse(algorithm.TryGetRootVertex(out _));

            var vertex = new TVertex();

            algorithm.SetRootVertex(vertex);
            Assert.IsTrue(algorithm.TryGetRootVertex(out TVertex root));
            AssertEqual(vertex, root);
        }
コード例 #5
0
        protected static void ComputeWithoutRoot_Throws_Test <TVertex, TGraph>(
            [NotNull, InstantHandle] Func <RootedAlgorithmBase <TVertex, TGraph> > createAlgorithm)
            where TVertex : new()
            where TGraph : IImplicitVertexSet <TVertex>
        {
            RootedAlgorithmBase <TVertex, TGraph> algorithm = createAlgorithm();

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

            // Source vertex set but not to a vertex in the graph
            algorithm = createAlgorithm();
            algorithm.SetRootVertex(new TVertex());
            Assert.Throws <VertexNotFoundException>(algorithm.Compute);
        }