Exemplo n.º 1
0
        internal void EnumerateVertices(GraphParameter <Graph> p)
        {
            SimpleIncidenceGraph graph = p.Graph;

            // Arrange

            int source = graph.VertexCount >> 1;

            byte[] setBackingStore = ArrayPool <byte> .Shared.Rent(Math.Max(graph.VertexCount, source + 1));

            Array.Clear(setBackingStore, 0, setBackingStore.Length);
            IndexedSet exploredSet = new(setBackingStore);

            // Act

            IEnumerator <int> basicSteps      = Bfs.EnumerateVertices(graph, source, graph.VertexCount) !;
            IEnumerator <int> enumerableSteps = EnumerableBfs.EnumerateVertices(graph, source, exploredSet) !;

            // Assert

            while (true)
            {
                bool expectedHasCurrent = enumerableSteps.MoveNext();
                bool actualHasCurrent   = basicSteps.MoveNext();

                Assert.Equal(expectedHasCurrent, actualHasCurrent);

                if (!expectedHasCurrent || !actualHasCurrent)
                {
                    break;
                }

                int expected = enumerableSteps.Current;
                int actual   = basicSteps.Current;

                if (expected != actual)
                {
                    Assert.Equal(expected, actual);
                    break;
                }
            }
        }