Пример #1
0
        public void TestMatchAgainstItself()
        {
            var    m_atom1 = new Mock <IElectronContainer>(); IElectronContainer atom1 = m_atom1.Object;
            string result = ElectronContainerDiff.Diff(atom1, atom1);

            AssertZeroLength(result);
        }
Пример #2
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 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);
            }
        }
Пример #3
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 IAtomContainer && second is IAtomContainer))
            {
                return(null);
            }
            var firstAC   = (IAtomContainer)first;
            var secondAC  = (IAtomContainer)second;
            var totalDiff = new ChemObjectDifference("AtomContainerDiff");

            totalDiff.AddChild(IntegerDifference.Construct("atomCount", firstAC.Atoms.Count, secondAC.Atoms.Count));
            if (firstAC.Atoms.Count == secondAC.Atoms.Count)
            {
                for (int i = 0; i < firstAC.Atoms.Count; i++)
                {
                    totalDiff.AddChild(AtomDiff.Difference(firstAC.Atoms[i], secondAC.Atoms[i]));
                }
            }
            totalDiff.AddChild(IntegerDifference.Construct("electronContainerCount", firstAC.GetElectronContainers().Count(),
                                                           secondAC.GetElectronContainers().Count()));
            if (firstAC.GetElectronContainers().Count() == secondAC.GetElectronContainers().Count())
            {
                for (int i = 0; i < firstAC.GetElectronContainers().Count(); i++)
                {
                    if (firstAC.GetElectronContainers().ElementAt(i) is IBond &&
                        secondAC.GetElectronContainers().ElementAt(i) is IBond)
                    {
                        totalDiff.AddChild(BondDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                               secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else if (firstAC.GetElectronContainers().ElementAt(i) is ILonePair &&
                             secondAC.GetElectronContainers().ElementAt(i) is ILonePair)
                    {
                        totalDiff.AddChild(LonePairDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                   secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else if (firstAC.GetElectronContainers().ElementAt(i) is ISingleElectron &&
                             secondAC.GetElectronContainers().ElementAt(i) is ISingleElectron)
                    {
                        totalDiff.AddChild(SingleElectronDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                         secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else
                    {
                        totalDiff.AddChild(ElectronContainerDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                            secondAC.GetElectronContainers().ElementAt(i)));
                    }
                }
            }
            totalDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        public void TestDifference()
        {
            var m_ec1 = new Mock <IElectronContainer>(); IElectronContainer ec1 = m_ec1.Object;
            var m_ec2 = new Mock <IElectronContainer>(); IElectronContainer ec2 = m_ec2.Object;

            m_ec1.SetupGet(n => n.ElectronCount).Returns(2);
            m_ec2.SetupGet(n => n.ElectronCount).Returns(3);

            IDifference difference = ElectronContainerDiff.Difference(ec1, ec2);

            Assert.IsNotNull(difference);
        }
Пример #5
0
        public void TestDiff()
        {
            var m_ec1 = new Mock <IElectronContainer>(); IElectronContainer ec1 = m_ec1.Object;
            var m_ec2 = new Mock <IElectronContainer>(); IElectronContainer ec2 = m_ec2.Object;

            m_ec1.SetupGet(n => n.ElectronCount).Returns(2);
            m_ec2.SetupGet(n => n.ElectronCount).Returns(3);

            string result = ElectronContainerDiff.Diff(ec1, ec2);

            Assert.IsNotNull(result);
            Assert.AreNotSame(0, result.Length);
            AssertContains(result, "ElectronContainerDiff");
            AssertContains(result, "eCount");
            AssertContains(result, "2/3");
        }
Пример #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 ILonePair && second is ILonePair))
            {
                return(null);
            }
            var firstB    = (ILonePair)first;
            var secondB   = (ILonePair)second;
            var totalDiff = new ChemObjectDifference("LonePairDiff");

            totalDiff.AddChild(AtomDiff.Difference(firstB.Atom, secondB.Atom));
            totalDiff.AddChild(ElectronContainerDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Пример #7
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 ISingleElectron && second is ISingleElectron))
            {
                return(null);
            }
            ISingleElectron firstB    = (ISingleElectron)first;
            ISingleElectron secondB   = (ISingleElectron)second;
            IDifferenceList totalDiff = new ChemObjectDifference("SingleElectronDiff");

            totalDiff.AddChild(AtomDiff.Difference(firstB.Atom, secondB.Atom));
            totalDiff.AddChild(ElectronContainerDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }