Пример #1
0
        public virtual void TestClone()
        {
            IChemObject chemObject = NewChemObject();
            //chemObject.Flag = CDKConstants.ISALIPHATIC, true;

            // test cloning of itself
            object clone = chemObject.Clone();

            Assert.IsTrue(clone is IChemObject);

            // test that everything has been cloned properly
            string diff = ChemObjectDiff.Diff(chemObject, (IChemObject)clone);

            Assert.IsNotNull(diff);
            Assert.AreEqual(0, diff.Length);
        }
Пример #2
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IElectronContainer && second is IElectronContainer))
            {
                return(null);
            }
            var firstEC   = (IElectronContainer)first;
            var secondEC  = (IElectronContainer)second;
            var totalDiff = new ChemObjectDifference("ElectronContainerDiff");

            totalDiff.AddChild(IntegerDifference.Construct("eCount", firstEC.ElectronCount,
                                                           secondEC.ElectronCount));
            totalDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        ///
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        /// </summary>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IElement && second is IElement))
            {
                return(null);
            }
            var firstElem  = (IElement)first;
            var secondElem = (IElement)second;
            var coDiff     = new ChemObjectDifference("ElementDiff");

            coDiff.AddChild(StringDifference.Construct("S", firstElem.Symbol, secondElem.Symbol));
            coDiff.AddChild(StringDifference.Construct("ID", firstElem.Id, secondElem.Id));
            coDiff.AddChild(IntegerDifference.Construct("AN", firstElem.AtomicNumber, secondElem.AtomicNumber));
            coDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (coDiff.ChildCount() > 0)
            {
                return(coDiff);
            }
            else
            {
                return(null);
            }
        }