Exemplo n.º 1
0
        /// <summary>
        /// Returns a List of all IChemObject inside a ChemFile.
        /// </summary>
        /// <returns>A list of all ChemObjects</returns>
        public static IEnumerable <IChemObject> GetAllChemObjects(IChemFile file)
        {
            //list.Add(file); // should not add the original file
            foreach (var sequence in file)
            {
                yield return(sequence);

                foreach (var o in ChemSequenceManipulator.GetAllChemObjects(sequence))
                {
                    yield return(o);
                }
            }
            yield break;
        }
        public void TestGetAllChemObjects_IChemSequence()
        {
            var list             = ChemSequenceManipulator.GetAllChemObjects(chemSequence);
            int molCount         = 0;
            int molSetCount      = 0;
            int reactionCount    = 0;
            int reactionSetCount = 0;
            int chemModelCount   = 0;

            foreach (var o in list)
            {
                //if (o is IAtom) ++atomCount;
                //if (o is IBond) ++bondCount;
                if (o is IAtomContainer)
                {
                    ++molCount;
                }
                else if (o is IChemObjectSet <IAtomContainer> )
                {
                    ++molSetCount;
                }
                else if (o is IReaction)
                {
                    ++reactionCount;
                }
                else if (o is IReactionSet)
                {
                    ++reactionSetCount;
                }
                else if (o is IChemModel)
                {
                    ++chemModelCount;
                }
                else
                {
                    Assert.Fail("Unexpected Object of type " + o.GetType());
                }
            }
            //Assert.AreEqual(3, atomCount);
            //Assert.AreEqual(1, bondCount);
            Assert.AreEqual(2, molCount);
            Assert.AreEqual(1, molSetCount);
            Assert.AreEqual(1, reactionCount);
            Assert.AreEqual(1, reactionSetCount);
            Assert.AreEqual(2, chemModelCount);
        }