Esempio n. 1
0
        public void CompareMoreThanTest()
        {
            DoubleValue value1 = new DoubleValue(13);
            DoubleValue value2 = new DoubleValue(12);

            Assert.AreEqual(1, value1.CompareTo(value2));
        }
Esempio n. 2
0
        public void CompareEqualsTest()
        {
            DoubleValue value1 = new DoubleValue(12);
            DoubleValue value2 = new DoubleValue(12);

            Assert.AreEqual(0, value1.CompareTo(value2));
        }
        public void DoubleValue_CompareTo_Varies_True()
        {
            DoubleValue variesValue = new DoubleValue(aDouble);

            variesValue.IsVaries = true;

            Assert.IsTrue(variesValue.CompareTo(_nonzeroValue) < 0);
        }
Esempio n. 4
0
        public int CompareTo(IndexValue other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            var typeComparison = Type.CompareTo(other.Type);

            if (typeComparison != 0)
            {
                return(typeComparison);
            }
            switch (Type)
            {
            case IndexValueType.String:
                return(string.Compare(StringValue, other.StringValue, StringComparison.Ordinal));

            case IndexValueType.StringArray:
                return(string.Compare(ValueAsString, other.ValueAsString, StringComparison.Ordinal));

            case IndexValueType.Bool:
                return(BooleanValue.CompareTo(other.BooleanValue));

            case IndexValueType.Int:
                return(IntegerValue.CompareTo(other.IntegerValue));

            case IndexValueType.IntArray:
                return(string.Compare(ValueAsString, other.ValueAsString, StringComparison.Ordinal));

            case IndexValueType.Long:
                return(LongValue.CompareTo(other.LongValue));

            case IndexValueType.Float:
                return(SingleValue.CompareTo(other.SingleValue));

            case IndexValueType.Double:
                return(DoubleValue.CompareTo(other.DoubleValue));

            case IndexValueType.DateTime:
                return(DateTimeValue.CompareTo(other.DateTimeValue));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public int CompareTo(object obj)
        {
            var typedObj = (AllSupportedPropertyTypesObject)obj;
            int result   = string.Compare(StringValue, typedObj.StringValue);

            if (result == 0)
            {
                result = IntValue.CompareTo(typedObj.IntValue);
            }
            if (result == 0)
            {
                result = Nullable.Compare(NullableIntValue, typedObj.NullableIntValue);
            }

            if (result == 0)
            {
                result = DoubleValue.CompareTo(typedObj.DoubleValue);
            }

            if (result == 0)
            {
                result = Nullable.Compare(NullableDoubleValue, typedObj.NullableDoubleValue);
            }

            if (result == 0)
            {
                result = DateTimeValue.CompareTo(typedObj.DoubleValue);
            }

            if (result == 0)
            {
                result = Nullable.Compare(NullableDateTimeValue, typedObj.NullableDateTimeValue);
            }

            if (result == 0)
            {
                // TODO: this is more correctly done by using SequenceCompareTo()
                //       method but this is only available from Standard 2.1 onwards.
                //       Use basic custom implementation for backward compatibility.
                //result =  ByteArrayValue.SequenceEqual(typedObj.ByteArrayValue);
            }

            return(result);
        }
Esempio n. 6
0
            // less than zero if x is-better-than y
            // larger than zero if y is-better-than x
            // zero if both are the same
            public int Compare(IScope x, IScope y)
            {
                IVariable quality1, quality2;

                if (x.Variables.TryGetValue(qualityParameterName, out quality1) &&
                    y.Variables.TryGetValue(qualityParameterName, out quality2))
                {
                    DoubleValue left  = quality1.Value as DoubleValue;
                    DoubleValue right = quality2.Value as DoubleValue;
                    var         res   = left.CompareTo(right);
                    if (maximization)
                    {
                        return(-res);    // in the maximization case the largest value should preceed all others in the sort order
                    }
                    else
                    {
                        return(res);
                    }
                }
                else
                {
                    throw new ArgumentException("Quality variable " + qualityParameterName + " not found.");
                }
            }
 public void DoubleValue_CompareTo_Indeterminate_True()
 {
     Assert.IsTrue(_defaultValue.CompareTo(_nonzeroValue) < 0);
 }
 public void DoubleValue_CompareTo_False_True()
 {
     Assert.IsTrue(_zeroValue.CompareTo(_nonzeroValue) < 0);
 }
 public void DoubleValue_CompareTo_ReferenceEquality()
 {
     Assert.IsTrue(_nonzeroValue.CompareTo(_nonzeroValue) == 0);
 }
Esempio n. 10
0
 public int CompareTo(INumeric other)
 {
     return(DoubleValue.CompareTo(other.DoubleValue));
 }
Esempio n. 11
0
 public void CompareMoreThanTest()
 {
     DoubleValue value1 = new DoubleValue(13);
     DoubleValue value2 = new DoubleValue(12);
     Assert.AreEqual(1, value1.CompareTo(value2));
 }
Esempio n. 12
0
 public void CompareEqualsTest()
 {
     DoubleValue value1 = new DoubleValue(12);
     DoubleValue value2 = new DoubleValue(12);
     Assert.AreEqual(0, value1.CompareTo(value2));
 }