Exemple #1
0
    public static void TestCompareTo()
    {
        // Int32 Boolean.CompareTo(Boolean)
        Boolean bTrue  = true;
        Boolean bFalse = false;

        Assert.True(bTrue.CompareTo(true) == 0);
        Assert.True(bFalse.CompareTo(false) == 0);
        Assert.False(bTrue.CompareTo(false) < 0);
        Assert.False(bFalse.CompareTo(true) > 0);
    }
Exemple #2
0
 static void TestCompareTo()
 {
     {
         Boolean t = true, f = false;
         Console.WriteLine(f.CompareTo(t) < 0);
     }
 }
        /// <summary>
        /// Compares this instance to a specified <see cref="SecsBool"/> object and returns an integer that indicates their relationship to one another.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public int CompareTo(SecsBool value)
        {
            if (value == null)
            {
                return(1);
            }

            return(_value.CompareTo(value._value));
        }
        public void CompareTo()
        {
            Boolean t = true, f = false;

            Assert.IsTrue(f.CompareTo(t) < 0, "f.CompareTo(t) < 0");
            Assert.IsTrue(f.CompareTo(f) == 0, "f.CompareTo(f)");
            Assert.IsTrue(t.CompareTo(t) == 0, "t.CompareTo(t) == 0");
            Assert.IsTrue(t.CompareTo(f) > 0, "t.CompareTo(f) > 0");
            Assert.IsTrue(t.CompareTo(null) > 0, "t.CompareTo(null) > 0");

            byte[] array = new byte [1] {
                0x02
            };
            bool t2 = BitConverter.ToBoolean(array, 0);

            Assert.IsTrue(f.CompareTo(t2) < 0, "f.CompareTo(t2) < 0");
            Assert.IsTrue(t2.CompareTo(t2) == 0, "t2.CompareTo(t2) == 0");
            Assert.IsTrue(t2.CompareTo(f) > 0, "t2.CompareTo(f) > 0");
            Assert.IsTrue(t2.CompareTo(null) > 0, "t2.CompareTo(null) > 0");
        }
Exemple #5
0
        /// <summary>
        /// Compares this instance to a specified <see cref="Bit"/> object and returns an
        /// integer that indicates their relationship to one another
        /// </summary>
        /// <param name="obj">A <see cref="Bit"/> object to compare to this instance</param>
        /// <returns>A signed integer that indicates the relative values of this instance and
        /// <paramref name="obj"/>. Return Value Condition Less than zero This instance is 0 and
        /// <paramref name="obj"/> is 1. Zero This instance and <paramref name="obj"/> are equal
        /// (either both are 1 or both are 0). Greater than zero This instance is 1 and
        /// <paramref name="obj"/> is 0</returns>
        public Int32 CompareTo(Object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            Bit otherBit = (Bit)obj;

            return(value.CompareTo(otherBit.value));
        }
Exemple #6
0
        override public int Compare(int recordNo1, int recordNo2)
        {
            Boolean valueNo1 = values[recordNo1];
            Boolean valueNo2 = values[recordNo2];

            if (valueNo1 == defaultValue || valueNo2 == defaultValue)
            {
                int bitCheck = CompareBits(recordNo1, recordNo2);
                if (0 != bitCheck)
                {
                    return(bitCheck);
                }
            }
            return(valueNo1.CompareTo(valueNo2));
            //return ((valueNo1 == valueNo2) ? 0 : ((false == valueNo1) ? -1 : 1)); // similar to Boolean.CompareTo(Boolean)
        }
    public bool PosTest3()
    {
        bool retVal = true;

        try
        {
            Boolean b0 = true;
            Boolean b1 = false;
            if (b0.CompareTo(b1) <= 0)
            {
                TestLibrary.TestFramework.LogError("003", "expect true.CompareTo(false) > 0");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
        public int Compare(string a, string b)
        {
            if (a == b)
            {
                return(0);
            }
            int     results        = 0;
            Match   matcha         = Regex.Match(a, pattern);
            Match   matchb         = Regex.Match(b, pattern);
            string  namea          = matcha.Groups["name"].Value;
            int     indexa         = 0;
            int     subindexa      = 0;
            Boolean isAindexInt    = int.TryParse(matcha.Groups["index"].Value, out indexa);
            Boolean isAsubindexInt = int.TryParse(matcha.Groups["subindex"].Value, out subindexa);
            string  nameb          = matchb.Groups["name"].Value;
            int     indexb         = 0;
            int     subindexb      = 0;
            Boolean isBindexInt    = int.TryParse(matchb.Groups["index"].Value, out indexb);
            Boolean isBsubindexInt = int.TryParse(matchb.Groups["subindex"].Value, out subindexb);

            results = namea.CompareTo(nameb);
            if (results == 0)
            {
                results = isAindexInt.CompareTo(isBindexInt);
                if (results == 0)
                {
                    results = indexa.CompareTo(indexb);
                    if (results == 0)
                    {
                        results = isAsubindexInt.CompareTo(isBsubindexInt);
                        if (results == 0)
                        {
                            results = subindexa.CompareTo(subindexb);
                        }
                    }
                }
            }
            return(results);
        }
Exemple #9
0
        public override int CompareValueTo(int recordNo, object value)
        {
            System.Diagnostics.Debug.Assert(0 <= recordNo, "Invalid record");
            System.Diagnostics.Debug.Assert(null != value, "null value");

            if (NullValue == value)
            {
                if (IsNull(recordNo))
                {
                    return(0);
                }
                return(1);
            }

            Boolean valueNo1 = values[recordNo];

            if ((defaultValue == valueNo1) && IsNull(recordNo))
            {
                return(-1);
            }
            return(valueNo1.CompareTo((Boolean)value));
            //return ((valueNo1 == valueNo2) ? 0 : ((false == valueNo1) ? -1 : 1)); // similar to Boolean.CompareTo(Boolean)
        }
 public static Boolean of(Boolean left, Boolean right)
 {
     return(left.CompareTo(right) < 0 ? right : left);
 }
Exemple #11
0
        /// <summary>
        /// Compares the given pattern members, throwing a "Type Error" whenever the comparison operator detects sematically incompatible members;
        /// </summary>
        internal static Int32 CompareRDFPatternMembers(RDFPatternMember left, RDFPatternMember right)
        {
            #region CornerCase Comparisons
            if (left == null)
            {
                if (right == null)
                {
                    return(0);
                }
                return(-1);
            }
            if (right == null)
            {
                return(1);
            }
            #endregion

            #region Effective  Comparisons

            #region RESOURCE/CONTEXT
            if (left is RDFResource || left is RDFContext)
            {
                //RESOURCE/CONTEXT VS RESOURCE/CONTEXT
                if (right is RDFResource || right is RDFContext)
                {
                    return(String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal));
                }

                //RESOURCE/CONTEXT VS "XSD:ANYURI" TYPED LITERAL
                if (right is RDFTypedLiteral && ((RDFTypedLiteral)right).Datatype.Equals(RDFModelEnums.RDFDatatype.XSD_ANYURI))
                {
                    return(String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal));
                }

                //RESOURCE/CONTEXT VS LITERAL
                return(-1);
            }
            #endregion

            #region PLAINLITERAL
            if (left is RDFPlainLiteral)
            {
                //PLAIN LITERAL VS RESOURCE/CONTEXT
                if (right is RDFResource || right is RDFContext)
                {
                    return(1);
                }

                //PLAIN LITERAL VS PLAIN LITERAL
                if (right is RDFPlainLiteral)
                {
                    return(String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal));
                }

                //PLAIN LITERAL VS "RDFS:LITERAL" OR "XSD:STRING" TYPED LITERAL
                if (((RDFTypedLiteral)right).Datatype.Equals(RDFModelEnums.RDFDatatype.RDFS_LITERAL) ||
                    ((RDFTypedLiteral)right).Datatype.Equals(RDFModelEnums.RDFDatatype.XSD_STRING))
                {
                    return(String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal));
                }

                //PLAIN LITERAL VS TYPED LITERAL
                return(-1);
            }
            #endregion

            #region TYPEDLITERAL
            //TYPED LITERAL VS RESOURCE/CONTEXT
            if (right is RDFResource || right is RDFContext)
            {
                //"XSD:ANYURI" TYPED LITERAL VS RESOURCE/CONTEXT
                if (left is RDFTypedLiteral && ((RDFTypedLiteral)left).Datatype.Equals(RDFModelEnums.RDFDatatype.XSD_ANYURI))
                {
                    return(String.Compare(((RDFTypedLiteral)left).Value, right.ToString(), StringComparison.Ordinal));
                }

                //TYPED LITERAL VS RESOURCE/CONTEXT
                return(1);
            }

            //TYPED LITERAL VS PLAIN LITERAL
            if (right is RDFPlainLiteral)
            {
                //"RDFS:LITERAL" OR "XSD:STRING" TYPED LITERAL VS PLAIN LITERAL
                if (((RDFTypedLiteral)left).Datatype.Equals(RDFModelEnums.RDFDatatype.RDFS_LITERAL) ||
                    ((RDFTypedLiteral)left).Datatype.Equals(RDFModelEnums.RDFDatatype.XSD_STRING))
                {
                    return(String.Compare(((RDFTypedLiteral)left).Value, right.ToString(), StringComparison.Ordinal));
                }

                //TYPED LITERAL VS PLAIN LITERAL
                return(1);
            }

            //TYPED LITERAL VS TYPED LITERAL
            //Detect left typed literal's category
            RDFModelEnums.RDFDatatype leftDType = ((RDFTypedLiteral)left).Datatype;
            Boolean isLeftDTypeBoolean          = leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_BOOLEAN);
            Boolean isLeftDTypeNumeric          = leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_BYTE) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_DECIMAL) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_DOUBLE) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_FLOAT) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_INT) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_INTEGER) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_LONG) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NEGATIVEINTEGER) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NONNEGATIVEINTEGER) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NONPOSITIVEINTEGER) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_POSITIVEINTEGER) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_SHORT) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDBYTE) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDINT) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDLONG) ||
                                                  leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDSHORT);
            Boolean isLeftDTypeDateTime = leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_DATE) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_DATETIME) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_GDAY) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_GMONTH) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_GMONTHDAY) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_GYEAR) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_GYEARMONTH) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_TIME);
            Boolean isLeftDTypeTimeSpan = leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_DURATION);
            Boolean isLeftDTypeString   = leftDType.Equals(RDFModelEnums.RDFDatatype.RDFS_LITERAL) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.RDF_XMLLITERAL) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_ANYURI) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_BASE64BINARY) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_HEXBINARY) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_LANGUAGE) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NAME) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NCNAME) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NMTOKEN) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NORMALIZEDSTRING) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_NOTATION) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_QNAME) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_STRING) ||
                                          leftDType.Equals(RDFModelEnums.RDFDatatype.XSD_TOKEN);

            //Detect right typed literal's category
            RDFModelEnums.RDFDatatype rightDType = ((RDFTypedLiteral)right).Datatype;
            Boolean isRightDTypeBoolean          = rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_BOOLEAN);
            Boolean isRightDTypeNumeric          = rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_BYTE) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_DECIMAL) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_DOUBLE) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_FLOAT) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_INT) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_INTEGER) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_LONG) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NEGATIVEINTEGER) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NONNEGATIVEINTEGER) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NONPOSITIVEINTEGER) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_POSITIVEINTEGER) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_SHORT) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDBYTE) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDINT) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDLONG) ||
                                                   rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_UNSIGNEDSHORT);
            Boolean isRightDTypeDateTime = rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_DATE) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_DATETIME) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_GDAY) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_GMONTH) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_GMONTHDAY) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_GYEAR) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_GYEARMONTH) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_TIME);
            Boolean isRightDTypeTimeSpan = rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_DURATION);
            Boolean isRightDTypeString   = rightDType.Equals(RDFModelEnums.RDFDatatype.RDFS_LITERAL) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.RDF_XMLLITERAL) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_ANYURI) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_BASE64BINARY) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_HEXBINARY) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_LANGUAGE) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NAME) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NCNAME) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NMTOKEN) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NORMALIZEDSTRING) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_NOTATION) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_QNAME) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_STRING) ||
                                           rightDType.Equals(RDFModelEnums.RDFDatatype.XSD_TOKEN);

            //Compare typed literals, only if categories are semantically compatible
            if (isLeftDTypeBoolean && isRightDTypeBoolean)
            {
                Boolean leftValueBoolean  = Boolean.Parse(((RDFTypedLiteral)left).Value);
                Boolean rightValueBoolean = Boolean.Parse(((RDFTypedLiteral)right).Value);
                return(leftValueBoolean.CompareTo(rightValueBoolean));
            }
            else if (isLeftDTypeDateTime && isRightDTypeDateTime)
            {
                DateTime leftValueDateTime  = DateTime.Parse(((RDFTypedLiteral)left).Value, CultureInfo.InvariantCulture);
                DateTime rightValueDateTime = DateTime.Parse(((RDFTypedLiteral)right).Value, CultureInfo.InvariantCulture);
                return(leftValueDateTime.CompareTo(rightValueDateTime));
            }
            else if (isLeftDTypeNumeric && isRightDTypeNumeric)
            {
                Decimal leftValueDecimal  = Decimal.Parse(((RDFTypedLiteral)left).Value, CultureInfo.InvariantCulture);
                Decimal rightValueDecimal = Decimal.Parse(((RDFTypedLiteral)right).Value, CultureInfo.InvariantCulture);
                return(leftValueDecimal.CompareTo(rightValueDecimal));
            }
            else if (isLeftDTypeString && isRightDTypeString)
            {
                String leftValueString  = ((RDFTypedLiteral)left).Value;
                String rightValueString = ((RDFTypedLiteral)right).Value;
                return(leftValueString.CompareTo(rightValueString));
            }
            else if (isLeftDTypeTimeSpan && isRightDTypeTimeSpan)
            {
                TimeSpan leftValueDuration  = XmlConvert.ToTimeSpan(((RDFTypedLiteral)left).Value);
                TimeSpan rightValueDuration = XmlConvert.ToTimeSpan(((RDFTypedLiteral)right).Value);
                return(leftValueDuration.CompareTo(rightValueDuration));
            }
            else
            {
                throw new RDFQueryException("Type Error: Typed Literal of datatype (" + RDFModelUtilities.GetDatatypeFromEnum(leftDType) + ") cannot be compared to Typed Literal of datatype (" + RDFModelUtilities.GetDatatypeFromEnum(rightDType) + ")");
            }
            #endregion

            #endregion
        }
Exemple #12
0
        public static int compareTo(object o1, object o2)
        {
            try {
                if (o1 == null || o2 == null)
                {
                    return(0);
                }
                if (!Types.Equals(o1, o1))
                {
                    return(0);
                }

                if (o1 is bool)
                {
                    bool v1 = (bool)o1;
                    bool v2 = (bool)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Boolean)
                {
                    Boolean v1 = (Boolean)o1;
                    bool    v2 = (Boolean)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is byte)
                {
                    byte v1 = (byte)o1;
                    byte v2 = (byte)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Byte)
                {
                    Byte v1 = (Byte)o1;
                    Byte v2 = (Byte)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is short)
                {
                    short v1 = (short)o1;
                    short v2 = (short)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Int16)
                {
                    Int16 v1 = (Int16)o1;
                    Int16 v2 = (Int16)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is UInt16)
                {
                    UInt16 v1 = (UInt16)o1;
                    UInt16 v2 = (UInt16)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is int)
                {
                    int v1 = (int)o1;
                    int v2 = (int)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Int32)
                {
                    Int32 v1 = (Int32)o1;
                    Int32 v2 = (Int32)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is UInt32)
                {
                    UInt32 v1 = (UInt32)o1;
                    UInt32 v2 = (UInt32)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is long)
                {
                    long v1 = (long)o1;
                    long v2 = (long)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Int64)
                {
                    Int64 v1 = (Int64)o1;
                    Int64 v2 = (Int64)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is UInt64)
                {
                    UInt64 v1 = (UInt64)o1;
                    UInt64 v2 = (UInt64)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is float)
                {
                    float v1 = (float)o1;
                    float v2 = (float)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is double)
                {
                    double v1 = (double)o1;
                    double v2 = (double)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is string)
                {
                    string v1 = (string)o1;
                    string v2 = (string)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is String)
                {
                    String v1 = (String)o1;
                    String v2 = (String)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is DateTime)
                {
                    DateTime v1 = (DateTime)o1;
                    DateTime v2 = (DateTime)o2;
                    return(v1.CompareTo(v2));
                }
            } catch (Exception) {
            }
            return(0);
        }
 private static void Compare_Boolean(Boolean a, Boolean b) =>
 AssertEquals(a.CompareTo(b), Comparer <Boolean> .Default.Compare(a, b));
Exemple #14
0
    public static void Main()
    {
        string nl  = Environment.NewLine;
        string msg = "{0}The following is the result of using the generic and non-generic{0}" +
                     "versions of the CompareTo method for several base types:{0}";

        DateTime now = DateTime.Now;
// Time span = 11 days, 22 hours, 33 minutes, 44 seconds
        TimeSpan tsX = new TimeSpan(11, 22, 33, 44);
// Version = 1.2.333.4
        Version versX = new Version("1.2.333.4");
// Guid = CA761232-ED42-11CE-BACD-00AA0057B223
        Guid guidX = new Guid("{CA761232-ED42-11CE-BACD-00AA0057B223}");

        Boolean  a1 = true, a2 = true;
        Byte     b1 = 1, b2 = 1;
        Int16    c1 = -2, c2 = 2;
        Int32    d1 = 3, d2 = 3;
        Int64    e1 = 4, e2 = -4;
        Decimal  f1 = -5.5m, f2 = 5.5m;
        Single   g1 = 6.6f, g2 = 6.6f;
        Double   h1 = 7.7d, h2 = -7.7d;
        Char     i1 = 'A', i2 = 'A';
        String   j1 = "abc", j2 = "abc";
        DateTime k1 = now, k2 = now;
        TimeSpan l1 = tsX, l2 = tsX;
        Version  m1 = versX, m2 = new Version("2.0");
        Guid     n1 = guidX, n2 = guidX;

// The following types are not CLS-compliant.
        SByte  w1 = 8, w2 = 8;
        UInt16 x1 = 9, x2 = 9;
        UInt32 y1 = 10, y2 = 10;
        UInt64 z1 = 11, z2 = 11;

//
        Console.WriteLine(msg, nl);
        try
        {
// The second and third Show method call parameters are automatically boxed because
// the second and third Show method declaration arguments expect type Object.

            Show("Boolean:  ", a1, a2, a1.CompareTo(a2), a1.CompareTo((Object)a2));
            Show("Byte:     ", b1, b2, b1.CompareTo(b2), b1.CompareTo((Object)b2));
            Show("Int16:    ", c1, c2, c1.CompareTo(c2), c1.CompareTo((Object)c2));
            Show("Int32:    ", d1, d2, d1.CompareTo(d2), d1.CompareTo((Object)d2));
            Show("Int64:    ", e1, e2, e1.CompareTo(e2), e1.CompareTo((Object)e2));
            Show("Decimal:  ", f1, f2, f1.CompareTo(f2), f1.CompareTo((Object)f2));
            Show("Single:   ", g1, g2, g1.CompareTo(g2), g1.CompareTo((Object)g2));
            Show("Double:   ", h1, h2, h1.CompareTo(h2), h1.CompareTo((Object)h2));
            Show("Char:     ", i1, i2, i1.CompareTo(i2), i1.CompareTo((Object)i2));
            Show("String:   ", j1, j2, j1.CompareTo(j2), j1.CompareTo((Object)j2));
            Show("DateTime: ", k1, k2, k1.CompareTo(k2), k1.CompareTo((Object)k2));
            Show("TimeSpan: ", l1, l2, l1.CompareTo(l2), l1.CompareTo((Object)l2));
            Show("Version:  ", m1, m2, m1.CompareTo(m2), m1.CompareTo((Object)m2));
            Show("Guid:     ", n1, n2, n1.CompareTo(n2), n1.CompareTo((Object)n2));
//
            Console.WriteLine("{0}The following types are not CLS-compliant:", nl);
            Show("SByte:    ", w1, w2, w1.CompareTo(w2), w1.CompareTo((Object)w2));
            Show("UInt16:   ", x1, x2, x1.CompareTo(x2), x1.CompareTo((Object)x2));
            Show("UInt32:   ", y1, y2, y1.CompareTo(y2), y1.CompareTo((Object)y2));
            Show("UInt64:   ", z1, z2, z1.CompareTo(z2), z1.CompareTo((Object)z2));
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
Exemple #15
0
        private static bool ValueComparer(object obj1, object obj2, Type DataType)
        {
            bool   isValid      = false;
            string DataTypeName = "";

            DataTypeName = DataType.Name.ToString();
            if (obj1 == null && obj2 != null)
            {
                return(false);
            }
            else if (obj2 == null && obj1 != null)
            {
                return(false);
            }



            switch (DataTypeName)
            {
            case "Int32":
                Int32 val1, val2;
                val1 = (Int32)obj1;
                val2 = (Int32)obj2;
                if (val1 == val2)
                {
                    isValid = true;
                }
                break;

            case "String":
                string strval1, strval2;
                strval1 = (string)obj1;
                strval2 = (string)obj2;
                if (string.IsNullOrEmpty(strval1) == true)
                {
                    strval1 = "";
                }
                if (string.IsNullOrEmpty(strval2) == true)
                {
                    strval2 = "";
                }

                if (strval1.ToUpper() == strval2.ToUpper())
                {
                    isValid = true;
                }
                break;

            case "Guid":
                //TODO : Check ID
                //Guid guidval1 = new Guid(obj1.ToString());
                //Guid guidval2 = new Guid(obj2.ToString());
                //if (guidval1.CompareTo(guidval2) == 0)
                //{
                //    isValid = true;
                //}
                //break;
                return(false);

            case "DateTime":
                DateTime dtVal1 = (DateTime)obj1;
                DateTime dtVal2 = (DateTime)obj2;
                if (dtVal1.CompareTo(dtVal2) == 0)
                {
                    isValid = true;
                }
                break;

            case "float":
                float fltVal1 = float.Parse(obj1.ToString());
                float fltVal2 = float.Parse(obj2.ToString());
                if (fltVal1.CompareTo(fltVal2) == 0)
                {
                    isValid = true;
                }
                break;

            case "Boolean":
                Boolean bltVal1 = Boolean.Parse(obj1.ToString());
                Boolean bltVal2 = Boolean.Parse(obj2.ToString());
                if (bltVal1.CompareTo(bltVal2) == 0)
                {
                    isValid = true;
                }
                break;

            default:
                return(false);
            }
            return(isValid);
        }
    public virtual bool runTest()
    {
        Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        int     iCountErrors    = 0;
        int     iCountTestcases = 0;
        String  strLoc          = "Loc_000oo";
        Boolean bool2a          = false;
        Boolean bool2b          = true;

        try {
LABEL_860_GENERAL:
            do
            {
                strLoc = "Loc_384eu";
                iCountTestcases++;
                if (bool2a.CompareTo(null) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_387wq! , return==" + bool2a.CompareTo(null));
                }
                iCountTestcases++;
                if (bool2b.CompareTo(null) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_382qu! ,return==" + bool2b.CompareTo(null));
                }
                strLoc = "Loc_819wy";
                bool2a = false;
                iCountTestcases++;
                if (bool2a.CompareTo(false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_281wu! , return==" + bool2a.CompareTo(false));
                }
                strLoc = "Loc_982qy";
                bool2a = true;
                iCountTestcases++;
                if (bool2a.CompareTo(true) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_391hw! ,return==" + bool2a.CompareTo(true));
                }
                strLoc = "Loc_734ww";
                bool2a = true;
                iCountTestcases++;
                if (bool2a.CompareTo(false) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_832hq! ,return==" + bool2a.CompareTo(false));
                }
                strLoc = "Loc_195ch";
                bool2a = false;
                iCountTestcases++;
                if (bool2a.CompareTo(true) >= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_128fh!");
                }
            } while (false);
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general);
        }
        if (iCountErrors == 0)
        {
            Console.Error.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.Error.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
Exemple #17
0
        /// <summary>
        /// Compares the given pattern members, throwing a "Type Error" whenever the comparison operator detects sematically incompatible members;
        /// </summary>
        internal static Int32 CompareRDFPatternMembers(RDFPatternMember left, RDFPatternMember right)
        {
            #region NULLS
            if (left == null)
            {
                if (right == null)
                {
                    return(0);
                }
                return(-1);
            }
            if (right == null)
            {
                return(1);
            }
            #endregion

            #region RESOURCE/CONTEXT
            if (left is RDFResource || left is RDFContext)
            {
                //RESOURCE/CONTEXT VS RESOURCE/CONTEXT/PLAINLITERAL
                if (right is RDFResource || right is RDFContext || right is RDFPlainLiteral)
                {
                    return(String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal));
                }

                //RESOURCE/CONTEXT VS TYPEDLITERAL
                else
                {
                    if (((RDFTypedLiteral)right).HasStringDatatype())
                    {
                        return(String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal));
                    }
                    return(-99); //Type Error
                }
            }
            #endregion

            #region PLAINLITERAL
            else if (left is RDFPlainLiteral)
            {
                //PLAINLITERAL VS RESOURCE/CONTEXT/PLAINLITERAL
                if (right is RDFResource || right is RDFContext || right is RDFPlainLiteral)
                {
                    return(String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal));
                }

                //PLAINLITERAL VS TYPEDLITERAL
                else
                {
                    if (((RDFTypedLiteral)right).HasStringDatatype())
                    {
                        return(String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal));
                    }
                    return(-99); //Type Error
                }
            }
            #endregion

            #region TYPEDLITERAL
            else
            {
                //TYPEDLITERAL VS RESOURCE/CONTEXT/PLAINLITERAL
                if (right is RDFResource || right is RDFContext || right is RDFPlainLiteral)
                {
                    if (((RDFTypedLiteral)left).HasStringDatatype())
                    {
                        return(String.Compare(((RDFTypedLiteral)left).Value, right.ToString(), StringComparison.Ordinal));
                    }
                    return(-99); //Type Error
                }

                //TYPEDLITERAL VS TYPEDLITERAL
                else
                {
                    if (((RDFTypedLiteral)left).HasBooleanDatatype() && ((RDFTypedLiteral)right).HasBooleanDatatype())
                    {
                        Boolean leftValueBoolean  = Boolean.Parse(((RDFTypedLiteral)left).Value);
                        Boolean rightValueBoolean = Boolean.Parse(((RDFTypedLiteral)right).Value);
                        return(leftValueBoolean.CompareTo(rightValueBoolean));
                    }
                    else if (((RDFTypedLiteral)left).HasDatetimeDatatype() && ((RDFTypedLiteral)right).HasDatetimeDatatype())
                    {
                        DateTime leftValueDateTime  = DateTime.Parse(((RDFTypedLiteral)left).Value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
                        DateTime rightValueDateTime = DateTime.Parse(((RDFTypedLiteral)right).Value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
                        return(leftValueDateTime.CompareTo(rightValueDateTime));
                    }
                    else if (((RDFTypedLiteral)left).HasDecimalDatatype() && ((RDFTypedLiteral)right).HasDecimalDatatype())
                    {
                        Decimal leftValueDecimal  = Decimal.Parse(((RDFTypedLiteral)left).Value, CultureInfo.InvariantCulture);
                        Decimal rightValueDecimal = Decimal.Parse(((RDFTypedLiteral)right).Value, CultureInfo.InvariantCulture);
                        return(leftValueDecimal.CompareTo(rightValueDecimal));
                    }
                    else if (((RDFTypedLiteral)left).HasStringDatatype() && ((RDFTypedLiteral)right).HasStringDatatype())
                    {
                        String leftValueString  = ((RDFTypedLiteral)left).Value;
                        String rightValueString = ((RDFTypedLiteral)right).Value;
                        return(leftValueString.CompareTo(rightValueString));
                    }
                    else if (((RDFTypedLiteral)left).HasTimespanDatatype() && ((RDFTypedLiteral)right).HasTimespanDatatype())
                    {
                        TimeSpan leftValueDuration  = XmlConvert.ToTimeSpan(((RDFTypedLiteral)left).Value);
                        TimeSpan rightValueDuration = XmlConvert.ToTimeSpan(((RDFTypedLiteral)right).Value);
                        return(leftValueDuration.CompareTo(rightValueDuration));
                    }
                    else
                    {
                        return(-99); //Type Error
                    }
                }
            }
            #endregion
        }