예제 #1
0
 public void TestCompareTo()
 {
     Assert.AreEqual(65535, MyUInt16_3.CompareTo(MyUInt16_2), "#1");
     Assert.AreEqual(0, MyUInt16_2.CompareTo(MyUInt16_2), "#2");
     Assert.AreEqual(0, MyUInt16_1.CompareTo((UInt16)(42)), "#3");
     Assert.AreEqual(-65535, MyUInt16_2.CompareTo(MyUInt16_3), "#4");
     try {
         MyUInt16_2.CompareTo((object)100);
         Assert.Fail("Should raise a System.ArgumentException");
     } catch (ArgumentException e) {
     }
 }
예제 #2
0
파일: UInt16Test.cs 프로젝트: raj581/Marvin
 public void TestCompareTo()
 {
     Assert.IsTrue(MyUInt16_3.CompareTo(MyUInt16_2) > 0);
     Assert.IsTrue(MyUInt16_2.CompareTo(MyUInt16_2) == 0);
     Assert.IsTrue(MyUInt16_1.CompareTo((UInt16)(42)) == 0);
     Assert.IsTrue(MyUInt16_2.CompareTo(MyUInt16_3) < 0);
     try {
         MyUInt16_2.CompareTo((object)100);
         Assert.Fail("Should raise a System.ArgumentException");
     }
     catch (Exception e) {
         Assert.IsTrue(typeof(ArgumentException) == e.GetType());
     }
 }
예제 #3
0
        public void testCompareTo1()
        {
            UInt16 a = 5;
            UInt16 b = 6;
            var    x = a.CompareTo(b);

            AssertTrue(x < 0);
        }
예제 #4
0
        /// <summary>
        /// Compares this instance to a specified <see cref="SecsUInt16"/> object and returns an integer that indicates their relationship to one another.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public int CompareTo(SecsUInt16 value)
        {
            if (value == null)
            {
                return(1);
            }

            return(_value.CompareTo(value._value));
        }
예제 #5
0
        private void MethodTests()
        {
            featureTest.FailureMessage = "\tFailed UInt16 Method Test";
            featureTest.Send("UInt16 Method Test");
            UInt16 value1 = 1;
            UInt16 value2 = 2;
            UInt16 value3 = 3;
            Object obj1   = value1;
            Object obj2   = value2;
            Object obj3   = value3;

            featureTest.AssertTrue(value2.CompareTo(value1) > 0);
            featureTest.AssertTrue(value2.CompareTo(value3) < 0);
            featureTest.AssertTrue(value2.CompareTo(value2) == 0);

            featureTest.AssertTrue(value2.CompareTo(obj1) > 0);
            featureTest.AssertTrue(value2.CompareTo(obj3) < 0);
            featureTest.AssertTrue(value2.CompareTo(obj2) == 0);

            featureTest.AssertTrue(!value2.Equals(value1));
            featureTest.AssertTrue(!value2.Equals(value3));
            featureTest.AssertTrue(value2.Equals(value2));

            featureTest.AssertTrue(!value2.Equals(obj1));
            featureTest.AssertTrue(!value2.Equals(obj3));
            featureTest.AssertTrue(value2.Equals(obj2));
            featureTest.AssertTrue(UInt16.Parse("33") == 33);
            String str = 35.ToString();

            featureTest.AssertTrue(str == "35");
            UInt16 parsed;

            featureTest.AssertTrue(UInt16.TryParse(str, out parsed));
            featureTest.AssertTrue(parsed == 35);
        }
예제 #6
0
                public int CompareTo(Range rhs)
                {
                    int result = First.CompareTo(rhs.First);

                    if (result == 0)
                    {
                        result = Last.CompareTo(rhs.Last);
                    }
                    if (result == 0)
                    {
                        result = TracebackID.CompareTo(rhs.TracebackID);
                    }
                    return(result);
                }
예제 #7
0
        public int CompareTo(SectionContrib40 other)
        {
            if (this.SectionIndex == other.SectionIndex)
            {
                // offset >= and within section size
                if (other.Offset - Offset < Size)
                {
                    return(0);
                }

                return(this.Offset.CompareTo(other.Offset));
            }

            return(SectionIndex.CompareTo(other.SectionIndex));
        }
예제 #8
0
    public static void TestCompareTo()
    {
        UInt16 i = 234;

        Assert.Equal(0, i.CompareTo((UInt16)234));

        Assert.True(i.CompareTo(UInt16.MinValue) > 0);
        Assert.True(i.CompareTo((UInt16)0) > 0);
        Assert.True(i.CompareTo((UInt16)123) > 0);
        Assert.True(i.CompareTo((UInt16)456) < 0);
        Assert.True(i.CompareTo(UInt16.MaxValue) < 0);
    }
예제 #9
0
        /// <summary>
        /// Compares two instances of this object.
        /// </summary>
        /// <param name="HourMin">An object to compare with.</param>
        public Int32 CompareTo(HourMin HourMin)
        {
            if ((Object)HourMin == null)
            {
                throw new ArgumentNullException("The given HourMin must not be null!");
            }

            // Compare CountryIds
            var _Result = _Hour.CompareTo(HourMin._Hour);

            // If equal: Compare OperatorIds
            if (_Result == 0)
            {
                _Result = _Minute.CompareTo(HourMin._Minute);
            }

            return(_Result);
        }
예제 #10
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)
            {
                return(HasValue(recordNo) ? 1 : 0);
            }

            UInt16 valueNo1 = values[recordNo];

            if ((defaultValue == valueNo1) && !HasValue(recordNo))
            {
                return(-1);
            }
            return(valueNo1.CompareTo((UInt16)value));
            //return ((int)valueNo1 - (int)valueNo2); // copied from UInt16.CompareTo(UInt16)
        }
예제 #11
0
        /// <summary>
        /// Compares two instances of this object.
        /// </summary>
        /// <param name="Currency">An object to compare with.</param>
        public Int32 CompareTo(Currency Currency)
        {
            if ((Object)Currency == null)
            {
                throw new ArgumentNullException("The given Currency must not be null!");
            }

            var Result = _ISOCode.CompareTo(Currency._ISOCode);

            if (Result == 0)
            {
                Result = _Numeric.CompareTo(Currency._Numeric);
            }

            if (Result == 0)
            {
                Result = _Name.CompareTo(Currency._Name);
            }

            return(Result);
        }
예제 #12
0
    public bool PosTest2()
    {
        bool retVal = true;
        int  ActualResult;

        TestLibrary.TestFramework.BeginScenario("PosTest2: UInt16 value is less than the instance");
        try
        {
            UInt16 uintA    = 0xffff;
            UInt16 comValue = (UInt16)this.GetInt32(0, UInt16.MaxValue);
            ActualResult = uintA.CompareTo(comValue);
            if (ActualResult <= 0)
            {
                TestLibrary.TestFramework.LogError("003", "the ActualResult is not the ExpectResult");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
예제 #13
0
    public bool PosTest3()
    {
        bool retVal = true;
        int  ActualResult;

        TestLibrary.TestFramework.BeginScenario("PosTest3: UInt16 value is equal the instance");
        try
        {
            UInt16 uintA    = 0xffff;
            UInt16 comValue = UInt16.MaxValue;
            ActualResult = uintA.CompareTo(comValue);
            if (ActualResult != 0)
            {
                TestLibrary.TestFramework.LogError("005", "the ActualResult is not the ExpectResult");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unexpect exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
예제 #14
0
 /// <summary>
 ///     A T extension method that check if the value is between (exclusif) the minValue and maxValue.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="minValue">The minimum value.</param>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns>
 /// ###
 /// <typeparam name="T">Generic type parameter.</typeparam>
 public static bool Between(this UInt16 @this, UInt16 minValue, UInt16 maxValue)
 {
     return(minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1);
 }
예제 #15
0
파일: ScpUtil.cs 프로젝트: tuutuu803/ScpDS3
 public virtual int CompareTo(BthHandle other)
 {
     return(m_Value.CompareTo(other.m_Value));
 }
 /// <summary>
 ///     A T extension method that check if the value is between inclusively the minValue and maxValue.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="minValue">The minimum value.</param>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>true if the value is between inclusively the minValue and maxValue, otherwise false.</returns>
 /// ###
 /// <typeparam name="T">Generic type parameter.</typeparam>
 public static bool InRange(this UInt16 @this, UInt16 minValue, UInt16 maxValue)
 {
     return(@this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue) <= 0);
 }
예제 #17
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);
        }
예제 #18
0
 private static void Compare_UInt16(UInt16 a, UInt16 b) =>
 AssertEquals(a.CompareTo(b), Comparer <UInt16> .Default.Compare(a, b));
예제 #19
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);
        }
    }
예제 #20
0
 public CTDAFunction FunctionByIndex(UInt16 index)
 {
     return(CollectionHelpers.BinarySearch(ctdaFunctions, fn => {
         return index.CompareTo(fn.index);
     }));
 }
예제 #21
0
 public int CompareTo(ushort other)
 {
     return(value.CompareTo(other));
 }
예제 #22
0
    public Boolean runTest()
    {
        Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strComponentBeingTested + "  ,Source ver " + s_strDtTmVer);
        String strLoc          = "Loc_000ooo";
        int    iCountTestcases = 0;
        int    iCountErrors    = 0;

        if (verbose)
        {
            Console.WriteLine("Testing Method: UInt16.CompareTo( Object )");
        }
        try {
            UInt16[] baseValues =
            {
                UInt16.MinValue,
                UInt16.MinValue,
                UInt16.MinValue,
                UInt16.MaxValue,
                UInt16.MaxValue,
                UInt16.MaxValue,
                UInt16.MinValue,
                UInt16.MaxValue,
            };
            Object[] testValues =
            {
                UInt16.MinValue,
                (UInt16)100,
                UInt16.MaxValue,
                UInt16.MinValue,
                (UInt16)100,
                UInt16.MaxValue,
                null,
                null,
            };
            Int32[] expectedValues =
            {
                0,
                -1,
                -1,
                1,
                1,
                0,
                1,
                1,
            };
            for (int i = 0; i < testValues.Length; i++)
            {
                iCountTestcases++;
                if (verbose)
                {
                    Console.Write("Testing " + testValues[i] + " ==> ");
                }
                try {
                    Int32 result = baseValues[i].CompareTo(testValues[i]);
                    if (verbose)
                    {
                        Console.WriteLine("'" + expectedValues[i] + "' == '" + result + "'");
                    }
                    if (!result.Equals(expectedValues[i]) &&
                        !(result > 0 && expectedValues[i] > 0) &&
                        !(result < 0 && expectedValues[i] < 0))
                    {
                        iCountErrors++;
                        strLoc = "Err_VN1," + i;
                        Console.Error.WriteLine(strLoc + " Expected = '" + expectedValues[i] +
                                                "' ... Received = '" + result + "'.");
                    }
                } catch (Exception e) {
                    iCountErrors++;
                    strLoc = "Err_VE1," + i;
                    Console.Error.WriteLine(strLoc + " Exception Thrown: " + e.GetType().FullName);
                }
            }
            UInt16   baseValue          = UInt16.MinValue;
            String[] expectedExceptions =
            {
                "System.ArgumentException",
                "System.ArgumentException",
                "System.ArgumentException",
                "System.ArgumentException",
            };
            Object[] errorValues =
            {
                UInt32.MinValue,
                UInt64.MinValue,
                Int16.MinValue,
                Int16.MaxValue,
            };
            for (int i = 0; i < expectedExceptions.Length; i++)
            {
                iCountTestcases++;
                try {
                    if (verbose)
                    {
                        Console.WriteLine(" Exception Testing: " + expectedExceptions[i]);
                    }
                    Int32 result = baseValue.CompareTo(errorValues[i]);
                    iCountErrors++;
                    strLoc = "Err_NE1," + i;
                    Console.WriteLine(strLoc + " Exception not Thrown!");
                } catch (Exception e) {
                    if (!e.GetType().FullName.Equals(expectedExceptions[i]))
                    {
                        iCountErrors++;
                        strLoc = "Err_WE1," + i;
                        Console.WriteLine(strLoc + " Wrong Exception Thrown " + e.GetType().FullName);
                    }
                }
            }
        } catch (Exception e) {
            Console.WriteLine("Uncaught Exception in Int32 UInt16.CompareTo( Object )");
            Console.WriteLine("Exception->" + e.GetType().FullName);
        }
        Console.Error.Write(s_strTFName);
        Console.Error.Write(": ");
        if (iCountErrors == 0)
        {
            Console.Error.WriteLine(" iCountTestcases==" + iCountTestcases + " paSs");
            return(true);
        }
        else
        {
            Console.Error.WriteLine(s_strTFPath + s_strTFName + ".cs");
            Console.Error.WriteLine(" iCountTestcases==" + iCountTestcases);
            Console.Error.WriteLine("FAiL");
            Console.Error.WriteLine(" iCountErrors==" + iCountErrors);
            return(false);
        }
    }
예제 #23
0
 public static UInt16 of(UInt16 left, UInt16 right)
 {
     return(left.CompareTo(right) < 0 ? right : left);
 }
예제 #24
0
 public int CompareTo(FileEntry rhs)
 {
     return(NameIndex.CompareTo(rhs.NameIndex));
 }
예제 #25
0
 public int CompareTo(wushort value)
 {
     return(val.CompareTo(value.val));
 }