/// <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 IBond && second is IBond)) { return(null); } IBond firstB = (IBond)first; IBond secondB = (IBond)second; IDifferenceList totalDiff = new ChemObjectDifference("BondDiff"); totalDiff.AddChild(BondOrderDifference.Construct("order", firstB.Order, secondB.Order)); totalDiff.AddChild(IntegerDifference.Construct("atomCount", firstB.Atoms.Count, secondB.Atoms.Count)); if (firstB.Atoms.Count == secondB.Atoms.Count) { totalDiff.AddChild(AtomDiff.Difference(firstB.Begin, secondB.Begin)); totalDiff.AddChild(AtomDiff.Difference(firstB.End, secondB.End)); for (int i = 2; i < firstB.Atoms.Count; i++) { totalDiff.AddChild(AtomDiff.Difference(firstB.Atoms[i], secondB.Atoms[i])); } } totalDiff.AddChild(ElectronContainerDiff.Difference(first, second)); if (totalDiff.ChildCount() > 0) { return(totalDiff); } else { return(null); } }
public void TestCalculate_NoModifications() { var atom = Water.Atoms[1]; var clone = (IAtom)Water.Atoms[1].Clone(); Descriptor.Calculate(atom); var diff = AtomDiff.Diff(clone, atom); Assert.AreEqual(0, diff.Length, $"The descriptor must not change the passed atom in any respect, but found this diff: {diff}"); }
public void TestIElement_Symbol() { IAtomContainer mol = builder.NewAtomContainer(); IAtom atom = builder.NewAtom("C"); atom.Id = "a1"; mol.Atoms.Add(atom); IAtomContainer copy = CMLRoundTripTool.RoundTripMolecule(convertor, mol); string difference = AtomDiff.Diff(atom, copy.Atoms[0]); Assert.AreEqual(0, difference.Length, "Found non-zero diff: " + difference); }
public override void TestClone() { IAtom atom = (IAtom)NewChemObject(); object clone = atom.Clone(); Assert.IsTrue(clone is IAtom); // test that everything has been cloned properly string diff = AtomDiff.Diff(atom, (IAtom)clone); Assert.IsNotNull(diff); Assert.AreEqual(0, diff.Length); }
public void TestIAtom_FractionalPoint3d() { IAtomContainer mol = builder.NewAtomContainer(); IAtom atom = builder.NewAtom("C"); atom.Id = "a1"; atom.FractionalPoint3D = new Vector3(1, 2, 3); mol.Atoms.Add(atom); IAtomContainer copy = CMLRoundTripTool.RoundTripMolecule(convertor, mol); string difference = AtomDiff.Diff(atom, copy.Atoms[0]); Assert.AreEqual(0, difference.Length, "Found non-zero diff: " + difference); }