Beispiel #1
0
        public void TestMatchAgainstItself()
        {
            var    m_element1 = new Mock <IElement>(); IElement element1 = m_element1.Object;
            string result = ElementDiff.Diff(element1, element1);

            AssertZeroLength(result);
        }
Beispiel #2
0
        public virtual void TestCloneDiff()
        {
            IElement elem  = (IElement)NewChemObject();
            IElement clone = (IElement)elem.Clone();

            Assert.AreEqual("", ElementDiff.Diff(elem, clone));
        }
Beispiel #3
0
        public void TestDifference()
        {
            var m_element1 = new Mock <IElement>(); IElement element1 = m_element1.Object;
            var m_element2 = new Mock <IElement>(); IElement element2 = m_element2.Object;

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

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

            Assert.IsNotNull(difference);
        }
Beispiel #4
0
        public override void TestClone()
        {
            IElement elem  = (IElement)NewChemObject();
            object   clone = elem.Clone();

            Assert.IsTrue(clone is IElement);

            // test that everything has been cloned properly
            string diff = ElementDiff.Diff(elem, (IElement)clone);

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

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

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

            Assert.IsNotNull(result);
            Assert.AreNotSame(0, result.Length);
            AssertContains(result, "ElementDiff");
            AssertContains(result, "H/C");
        }
Beispiel #6
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 IIsotope && second is IIsotope))
            {
                return(null);
            }
            var firstElem  = (IIsotope)first;
            var secondElem = (IIsotope)second;
            var totalDiff  = new ChemObjectDifference("IsotopeDiff");

            totalDiff.AddChild(IntegerDifference.Construct("MN", firstElem.MassNumber, secondElem.MassNumber));
            totalDiff.AddChild(DoubleDifference.Construct("EM", firstElem.ExactMass, secondElem.ExactMass));
            totalDiff.AddChild(DoubleDifference.Construct("AB", firstElem.Abundance, secondElem.Abundance));
            totalDiff.AddChild(ElementDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }