/// <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); } IIsotope firstElem = (IIsotope)first; IIsotope secondElem = (IIsotope)second; ChemObjectDifference 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); } }
public void TestToString() { ChemObjectDifference diff = new ChemObjectDifference("AtomTypeDiff"); string diffString = diff.ToString(); Assert.IsNotNull(diffString); Assert.AreEqual(0, diffString.Length); diff.AddChild(StringDifference.Construct("Foo", "bar", "bar1")); diffString = diff.ToString(); Assert.IsNotNull(diffString); AssertOneLiner(diffString); AssertContains(diffString, "AtomTypeDiff"); AssertContains(diffString, "{"); AssertContains(diffString, "}"); }