示例#1
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 IAtomType && second is IAtomType))
            {
                return(null);
            }
            var firstElem  = (IAtomType)first;
            var secondElem = (IAtomType)second;
            var totalDiff  = new ChemObjectDifference("AtomTypeDiff");

            totalDiff.AddChild(StringDifference.Construct("N", firstElem.AtomTypeName, secondElem.AtomTypeName));
            totalDiff.AddChild(BondOrderDifference.Construct("MBO", firstElem.MaxBondOrder,
                                                             secondElem.MaxBondOrder));
            totalDiff
            .AddChild(DoubleDifference.Construct("BOS", firstElem.BondOrderSum, secondElem.BondOrderSum));
            totalDiff
            .AddChild(IntegerDifference.Construct("FC", firstElem.FormalCharge, secondElem.FormalCharge));
            totalDiff.AddChild(AtomTypeHybridizationDifference.Construct("H", firstElem.Hybridization,
                                                                         secondElem.Hybridization));
            totalDiff.AddChild(IntegerDifference.Construct("NC", firstElem.FormalNeighbourCount,
                                                           secondElem.FormalNeighbourCount));
            totalDiff.AddChild(DoubleDifference.Construct("CR", firstElem.CovalentRadius,
                                                          secondElem.CovalentRadius));
            totalDiff.AddChild(IntegerDifference.Construct("V", firstElem.Valency, secondElem.Valency));
            totalDiff.AddChild(IsotopeDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        public void TestMatchAgainstItself()
        {
            var    m_element1 = new Mock <IIsotope>(); IIsotope element1 = m_element1.Object;
            string result = IsotopeDiff.Diff(element1, element1);

            AssertZeroLength(result);
        }
示例#3
0
        public void TestDifference()
        {
            var m_element1 = new Mock <IIsotope>(); IIsotope element1 = m_element1.Object;
            var m_element2 = new Mock <IIsotope>(); IIsotope element2 = m_element2.Object;

            m_element1.SetupGet(n => n.Symbol).Returns("H");
            m_element2.SetupGet(n => n.Symbol).Returns("C");

            IDifference difference = IsotopeDiff.Difference(element1, element2);

            Assert.IsNotNull(difference);
        }
示例#4
0
        public override void TestClone()
        {
            IIsotope iso   = (IIsotope)NewChemObject();
            object   clone = iso.Clone();

            Assert.IsTrue(clone is IIsotope);

            // test that everything has been cloned properly
            string diff = IsotopeDiff.Diff(iso, (IIsotope)clone);

            Assert.IsNotNull(diff);
            Assert.AreEqual(0, diff.Length);
        }
示例#5
0
        public void TestDiff()
        {
            var m_element1 = new Mock <IIsotope>(); IIsotope element1 = m_element1.Object;
            var m_element2 = new Mock <IIsotope>(); IIsotope element2 = m_element2.Object;

            m_element1.SetupGet(n => n.Symbol).Returns("H");
            m_element2.SetupGet(n => n.Symbol).Returns("C");

            string result = IsotopeDiff.Diff(element1, element2);

            Assert.IsNotNull(result);
            Assert.AreNotSame(0, result.Length);
            AssertContains(result, "IsotopeDiff");
            AssertContains(result, "H/C");
        }