コード例 #1
0
        protected static void TryGetDistance_Throws_Test <TVertex, TEdge>(
            [NotNull] UndirectedShortestPathAlgorithmBase <TVertex, TEdge> algorithm)
            where TVertex : class, new()
            where TEdge : IEdge <TVertex>
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => algorithm.TryGetDistance(null, out _));

            var vertex = new TVertex();

            Assert.Throws <InvalidOperationException>(() => algorithm.TryGetDistance(vertex, out _));
        }
コード例 #2
0
        protected static void TryGetDistance_Test <TEdge>(
            [NotNull] UndirectedShortestPathAlgorithmBase <int, TEdge> algorithm)
            where TEdge : IEdge <int>
        {
            const int vertex1 = 1;

            algorithm.Compute(vertex1);
            Assert.IsTrue(algorithm.TryGetDistance(vertex1, out double distance));
            Assert.AreEqual(algorithm.Distances[vertex1], distance);

            const int vertex2 = 2;

            Assert.IsFalse(algorithm.TryGetDistance(vertex2, out _));
        }