AnalyzerUnitTest.ConnectedComponentCalculatorTest.CheckThatComponentConsistsOfVertices C# (CSharp) Method

CheckThatComponentConsistsOfVertices() protected method

protected CheckThatComponentConsistsOfVertices ( LinkedList oComponent ) : void
oComponent LinkedList
return void
        CheckThatComponentConsistsOfVertices
        (
            LinkedList<IVertex> oComponent,
            params Int32[] aiVertexIDs
        )
        {
            Assert.IsNotNull(oComponent != null);
            Assert.AreEqual(aiVertexIDs.Length, oComponent.Count);

            // The key is a vertex ID from aiVertexIDs and the value is false if
            // the ID hasn't been found yet in the component.

            Dictionary<Int32, Boolean> oVertexIDFlags =
                new Dictionary<Int32, Boolean>(aiVertexIDs.Length);

            foreach (Int32 iVertexID in aiVertexIDs)
            {
                oVertexIDFlags.Add(iVertexID, false);
            }

            foreach (IVertex oVertex in oComponent)
            {
                Int32 iVertexID = oVertex.ID;

                if (!oVertexIDFlags.ContainsKey(iVertexID))
                {
                    Assert.Fail("Unexpected vertex in component.");
                }

                if (oVertexIDFlags[iVertexID])
                {
                    Assert.Fail("Vertex in component two times.");
                }

                oVertexIDFlags[iVertexID] = true;
            }

            foreach (KeyValuePair<Int32, Boolean> oKeyValuePair in oVertexIDFlags)
            {
                if (!oKeyValuePair.Value)
                {
                    Assert.Fail("Expected vertex not found in component.");
                }
            }
        }