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); }
/// <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); } }