Exemplo n.º 1
0
        public void Should_not_possible_to_compare_elements_with_null_value()
        {
            FloatComparator comparator    = new FloatComparator();
            bool            compareResult = comparator.Compare("29", null, OperationEnumeration.equals);

            Assert.IsFalse(compareResult, "the value is not expected for this operation");
        }
Exemplo n.º 2
0
        public void Should_not_be_possible_two_compare_elements_that_is_not_float_with_any_operator()
        {
            FloatComparator comparator = new FloatComparator();

            bool compareResult = comparator.Compare("Is not a Float", "15", OperationEnumeration.greaterthanorequal);

            Assert.IsTrue(compareResult, "the value is not a float number");
        }
Exemplo n.º 3
0
        public void Should_be_possible_to_compare_two_floats_using_not_equals_operator()
        {
            FloatComparator comparator = new FloatComparator();

            bool compareResult = comparator.Compare("0.5", "0.55", OperationEnumeration.notequal);

            Assert.IsTrue(compareResult, "the value is not expected for not equals operation");

            compareResult = comparator.Compare("10", "11", OperationEnumeration.notequal);
            Assert.IsTrue(compareResult, "the value is not expected for not equals operation");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sorts the receiver according
        /// to the order induced by the specified comparatord  All elements in the
        /// range must be <i>mutually comparable</i> by the specified comparator
        /// (that is, <i>c.CompareTo(e1, e2)</i> must not throw a
        /// <i>ClassCastException</i> for any elements <i>e1</i> and
        /// <i>e2</i> in the range).<p>
        ///
        /// The sorting algorithm is a tuned quicksort,
        /// adapted from Jon Ld Bentley and Md Douglas McIlroy's "Engineering a
        /// Sort Function", Software-Practice and Experience, Vold 23(11)
        /// Pd 1249-1265 (November 1993)d  This algorithm offers n*log(n)
        /// performance on many data sets that cause other quicksorts to degrade to
        /// quadratic performance.
        ///
        /// <summary>
        /// <param name="from">the index of the first element (inclusive) to be</param>
        ///        sorted.
        /// <param name="to">the index of the last element (inclusive) to be sorted.</param>
        /// <param name="c">the comparator to determine the order of the receiver.</param>
        /// <exception cref="ClassCastException">if the array contains elements that are not </exception>
        ///	       <i>mutually comparable</i> using the specified comparator.
        /// <exception cref="ArgumentException">if <i>fromIndex &gt; toIndex</i> </exception>
        /// <exception cref="ArrayIndexOutOfRangeException">if <i>fromIndex &lt; 0</i> or </exception>
        ///	       <i>toIndex &gt; a.Length</i>
        /// <see cref="Comparator"></see>
        /// <exception cref="IndexOutOfRangeException">index is out of range (<i>_size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=_size())</i>). </exception>
        public virtual void QuickSortFromTo(int from, int to, FloatComparator c)
        {
            int mySize = Size;

            CheckRangeFromTo(from, to, mySize);

            var myElements = GetElements();

            Cern.Colt.Sorting.QuickSort(myElements, from, to + 1, c);
            SetElements(myElements);
            SetSizeRaw(mySize);
        }
Exemplo n.º 5
0
        public void Should_be_possible_to_compare_two_floats_using_equals_operator()
        {
            FloatComparator comparator = new FloatComparator();

            bool compareResult = comparator.Compare("55.89", "55.89", OperationEnumeration.equals);

            Assert.IsTrue(compareResult, "the value is not expected for equals operation");

            compareResult = comparator.Compare("10", "10", OperationEnumeration.equals);
            Assert.IsTrue(compareResult, "the value is not expected for equals operation");

            compareResult = comparator.Compare("55.89", "55.88", OperationEnumeration.equals);
            Assert.IsFalse(compareResult, "the value is not expected for equals operation");
        }
Exemplo n.º 6
0
        public void Should_be_possible_to_compare_two_floats_using_less_than_or_equals_operator()
        {
            FloatComparator comparator = new FloatComparator();

            bool compareResult = comparator.Compare("0.33", "0.33", OperationEnumeration.lessthanorequal);

            Assert.IsTrue(compareResult, "the value is not expected for less than operation");

            compareResult = comparator.Compare("50", "180", OperationEnumeration.lessthanorequal);
            Assert.IsTrue(compareResult, "the value is not expected for less than operation");

            compareResult = comparator.Compare("0.550", "0.550", OperationEnumeration.lessthanorequal);
            Assert.IsTrue(compareResult, "the value is not expected for less than operation");
        }
Exemplo n.º 7
0
        public void Should_be_possible_to_compare_two_floats_using_greather_than_or_equals_operator()
        {
            FloatComparator comparator = new FloatComparator();

            bool compareResult = comparator.Compare("0.33", "0.10", OperationEnumeration.greaterthanorequal);

            Assert.IsTrue(compareResult, "the value is not expected for greater than or equals operation");

            compareResult = comparator.Compare("0.33", "0.33", OperationEnumeration.greaterthanorequal);
            Assert.IsTrue(compareResult, "the value is not expected for greater than or equals operation");

            compareResult = comparator.Compare("0.1113", "0.1113", OperationEnumeration.greaterthanorequal);
            Assert.IsTrue(compareResult, "the value is not expected for greater than or equals operation");
        }
Exemplo n.º 8
0
        public void Should_be_possible_to_compare_two_floats_using_less_than_operator()
        {
            FloatComparator comparator = new FloatComparator();

            bool compareResult = comparator.Compare("0.33", "0.99", OperationEnumeration.lessthan);

            Assert.IsTrue(compareResult, "the value is not expected for less than operation");

            compareResult = comparator.Compare("50", "180", OperationEnumeration.lessthan);
            Assert.IsTrue(compareResult, "the value is not expected for less than operation");

            // error in convertion case of 0.850. It convert to 850.0
            compareResult = comparator.Compare("0.85", "180", OperationEnumeration.lessthan);
            Assert.IsTrue(compareResult, "the value is not expected for less than operation");
        }