Ejemplo n.º 1
0
        private static void TestCompareListsOfT <T>(int expectedValue, List <T> list1, List <T> list2)
            where T : IComparable
        {
            int result = ComparisonHelper.CompareLists <T>(list1, list2);

            Assert.Equal(expectedValue, result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compares the current object with another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// A value that indicates the relative order of the objects being compared. The
        /// return value has the following meanings:
        ///  * Less than zero: This object is less than <paramref name="other"/>.
        ///  * Zero: This object is equal to <paramref name="other"/>.
        ///  * Greater than zero: This object is greater than <paramref name="other"/>.
        ///  </returns>
        public override int CompareTo(GeneticEntity other)
        {
            if (other is null)
            {
                return(1);
            }

            if (!(other is ListEntityBase listEntityBase))
            {
                throw new ArgumentException(StringUtil.GetFormattedString(
                                                Resources.ErrorMsg_ObjectIsWrongType, typeof(ListEntityBase)), nameof(other));
            }

            return(ComparisonHelper.CompareLists(this, listEntityBase));
        }
Ejemplo n.º 3
0
        public void ComparisonHelper_CompareLists_NonIComparable()
        {
            Assert.Throws <InvalidOperationException>(
                () => ComparisonHelper.CompareLists(
                    (IList) new List <object> {
                new ComparisonHelperTest()
            }, new List <object> {
                2
            }));

            Assert.Throws <InvalidOperationException>(
                () => ComparisonHelper.CompareLists(
                    (IList) new List <object> {
                1
            }, new List <object> {
                new ComparisonHelperTest()
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Compares the current object with another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// A value that indicates the relative order of the objects being compared. The
        /// return value has the following meanings:
        ///  * Less than zero: This object is less than <paramref name="other"/>.
        ///  * Zero: This object is equal to <paramref name="other"/>.
        ///  * Greater than zero: This object is greater than <paramref name="other"/>.
        ///  </returns>
        public override int CompareTo(GeneticEntity other)
        {
            if (other is null)
            {
                return(1);
            }

            if (!(other is TreeEntityBase treeEntityBase))
            {
                throw new ArgumentException(StringUtil.GetFormattedString(
                                                Resources.ErrorMsg_ObjectIsWrongType, typeof(TreeEntityBase)), nameof(other));
            }

            List <TreeNode> thisTree  = this.GetPrefixTree().ToList();
            List <TreeNode> otherTree = treeEntityBase.GetPrefixTree().ToList();

            return(ComparisonHelper.CompareLists(
                       (IList)thisTree.Select(n => n.Value).ToList(),
                       (IList)otherTree.Select(n => n.Value).ToList()));
        }
Ejemplo n.º 5
0
        private static void TestCompareLists(int expectedValue, IList list1, IList list2)
        {
            int result = ComparisonHelper.CompareLists(list1, list2);

            Assert.Equal(expectedValue, result);
        }