public void TestCompareTo() { Assert.IsTrue(MyUInt32_3.CompareTo(MyUInt32_2) > 0); Assert.IsTrue(MyUInt32_2.CompareTo(MyUInt32_2) == 0); Assert.IsTrue(MyUInt32_1.CompareTo((UInt32)(42)) == 0); Assert.IsTrue(MyUInt32_2.CompareTo(MyUInt32_3) < 0); Assert.IsTrue(1 == UInt32.Parse("1")); Assert.IsTrue(1 == UInt32.Parse(" 1")); Assert.IsTrue(1 == UInt32.Parse(" 1")); Assert.IsTrue(1 == UInt32.Parse("1 ")); Assert.IsTrue(1 == UInt32.Parse("+1")); try { UInt32.Parse(" + 1 "); Assert.Fail("Should raise FormatException1"); } catch (Exception e) { Assert.IsTrue(typeof(FormatException) == e.GetType()); } try { UInt32.Parse(" + "); Assert.Fail("Should raise FormatException"); } catch (Exception e) { Assert.IsTrue(typeof(FormatException) == e.GetType()); } try { MyUInt32_2.CompareTo((object)(Int16)100); Assert.Fail("Should raise a System.ArgumentException"); } catch (Exception e) { Assert.IsTrue(typeof(ArgumentException) == e.GetType()); } }
internal static UInt32 Validate(this UInt32 value, UInt32 maxValue, Action <UInt32> reportError) { if (value.CompareTo(maxValue) >= 0) { reportError(value); } return(value & maxValue - 1); }
public int CompareTo(Object other) { int ret = 0; if (other is OUN) { ret = _value.CompareTo(((OUN)other).Value); } else if (other is UInt32) { ret = _value.CompareTo((UInt32)other); } else { throw new NotSupportedException(); } return(ret); }
/// <summary> /// Compares this instance to a specified <see cref="SecsUInt32"/> object and returns an integer that indicates their relationship to one another. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> public int CompareTo(SecsUInt32 value) { if (value == null) { return(1); } return(_value.CompareTo(value._value)); }
public int CompareTo(PropertyKey other) { int diff = PropSetId.CompareTo(other.PropSetId); if (diff != 0) { return(diff); } return(PropertyId.CompareTo(other.PropertyId)); }
public int CompareTo(AcceptType other) { if (_Quality == other._Quality) { return(_PlaceOfOccurence.CompareTo(other._PlaceOfOccurence)); } else { return(_Quality.CompareTo(other._Quality) * -1); } }
public override int Compare(T a, T b) { UInt32 aHash = (UInt32)a.GetHashCode(); UInt32 bHash = (UInt32)b.GetHashCode(); int value = aHash.CompareTo(bHash); if (value != 0) { return(value); } return(a.CompareTo(b)); }
public override int Compare(Movie a, Movie b) { UInt32 aHash = (UInt32)a.Title.GetHashCode(); UInt32 bHash = (UInt32)b.Title.GetHashCode(); int value = aHash.CompareTo(bHash); if (value != 0) { return(value); } return(a.Title.CompareTo(b.Title)); }
public static int CompareTo([JsFakeThis] UInt32 _this, object other) { if (other == null) { return(1); } if (!(other is UInt32)) { throw new ArgumentException(); } return(_this.CompareTo((UInt32)other)); }
public override int Compare(StoreBase a, StoreBase b) { UInt32 aHash = (UInt32)a.StoreName.GetHashCode(); UInt32 bHash = (UInt32)b.StoreName.GetHashCode(); int value = aHash.CompareTo(bHash); if (value != 0) { return(value); } return(a.StoreName.CompareTo(b.StoreName)); }
private void MethodTests() { featureTest.FailureMessage = "\tFailed UInt32 Method Test"; featureTest.Send("UInt32 Method Test"); UInt32 value1 = 1; UInt32 value2 = 2; UInt32 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(UInt32.Parse("33") == 33); String str = 35.ToString(); featureTest.AssertTrue(str == "35"); UInt32 parsed; featureTest.AssertTrue(UInt32.TryParse(str, out parsed)); featureTest.AssertTrue(parsed == 35); }
public int CompareTo(Object obj) { Event other = obj as Event; if (other.ProcessId == this.ProcessId) { return(localId.CompareTo(other.localId)); } else { return(timestamp.CompareTo(other.timestamp)); } }
int IComparable <KzUInt160> .CompareTo(KzUInt160 o) { var r = n2.CompareTo(o.n2); if (r == 0) { r = n1.CompareTo(o.n1); } if (r == 0) { r = n0.CompareTo(o.n0); } return(r); }
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); }
public int CompareTo(object obj) { // Make sure we are comparing to a valid object. if (obj == null || !(obj is ConnectionAddress)) { throw new NotSupportedException("Error: compared object is not a ConnectionAddress type!"); } // Convert addresses into numerical value for comparison. UInt32 left = this.AddressValue(); UInt32 right = ((ConnectionAddress)obj).AddressValue(); // Compare built in type. return(left.CompareTo(right)); }
/// <summary> /// Compares two instances of this object. /// </summary> /// <param name="AcceptType">An object to compare with.</param> public Int32 CompareTo(AcceptType AcceptType) { if ((Object)AcceptType == null) { throw new ArgumentNullException("The given AcceptType must not be null!"); } if (Quality == AcceptType.Quality) { return(_PlaceOfOccurence.CompareTo(AcceptType._PlaceOfOccurence)); } else { return(Quality.CompareTo(AcceptType.Quality) * -1); } }
public int CompareTo(BacnetObjectId other) { if (type == BacnetObjectTypes.OBJECT_DEVICE) { return(-1); } if (other.type == BacnetObjectTypes.OBJECT_DEVICE) { return(1); } if (type == other.type) { return(instance.CompareTo(other.instance)); } return(((int)(type)).CompareTo((int)other.type)); }
public static void TestCompareTo() { UInt32 i = 234; Assert.Equal(0, i.CompareTo((UInt32)234)); Assert.True(i.CompareTo(UInt32.MinValue) > 0); Assert.True(i.CompareTo((UInt32)0) > 0); Assert.True(i.CompareTo((UInt32)123) > 0); Assert.True(i.CompareTo((UInt32)456) < 0); Assert.True(i.CompareTo(UInt32.MaxValue) < 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); } UInt32 valueNo1 = values[recordNo]; if ((defaultValue == valueNo1) && !HasValue(recordNo)) { return(-1); } return(valueNo1.CompareTo((UInt32)value)); //return(valueNo1 < valueNo2 ? -1 : (valueNo1 > valueNo2 ? 1 : 0)); // similar to UInt32.CompareTo(UInt32) }
/// <include file='doc\UInt32Storage.uex' path='docs/doc[@for="UInt32Storage.CompareToValue"]/*' /> /// <internalonly/> override public int CompareToValue(int recordNo, Object value) { UInt32 valueNo1 = values[recordNo]; if (valueNo1 == UInt32Storage.defaultValue || value == null || value == DBNull.Value) { Object obj; if (valueNo1 == defaultValue) { obj = GetBits(recordNo); } else { obj = valueNo1; } if (obj == value) { return(0); } if (obj == null) { return(-1); } if (value == null) { return(1); } if (obj == DBNull.Value) { return(-1); } if (value == DBNull.Value) { return(1); } } UInt32 valueNo2 = Convert.ToUInt32(value); return(valueNo1.CompareTo(valueNo2)); }
public int ChainCompare(int[] cmp, NdxFile index, NdxEntry other) { this.Fields.ChainCompare(other.Fields, cmp); // to do check for ascending descending for (int i = 0; i < cmp.Length; i++) { if (cmp[i] != 0) { return(cmp[i]); } } // if we're here the fields are identical // we compare RecordNo when the index is NOT unique if (index.mNdxHeader.UniqueFlag) { return(0); } else { return(DbfRecordNo.CompareTo(other.DbfRecordNo)); } }
public bool PosTest4() { bool retVal = true; int ActualResult; TestLibrary.TestFramework.BeginScenario("PosTest4: UInt16 value is UInt16 min value"); try { UInt32 uintA = 0xffff; UInt32 comValue = UInt16.MinValue; ActualResult = uintA.CompareTo(comValue); if (ActualResult <= 0) { TestLibrary.TestFramework.LogError("007", "the ActualResult is not the ExpectResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpect exception:" + e); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; int ActualResult; TestLibrary.TestFramework.BeginScenario("PosTest2: object value is less than the instance"); try { UInt32 uintA = 0xffffffff; UInt32 comValue = (UInt32)this.GetInt32(0, Int32.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); }
public bool PosTest3() { bool retVal = true; int ActualResult; TestLibrary.TestFramework.BeginScenario("PosTest3: object value is equal the instance"); try { UInt32 uintA = 0xffffffff; UInt32 comValue = 4294967295; 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); }
private static void Compare_UInt32(UInt32 a, UInt32 b) => AssertEquals(a.CompareTo(b), Comparer <UInt32> .Default.Compare(a, b));
public int CompareTo(Codepoint other) { return(Value.CompareTo(other.Value)); }
/// <summary> /// Compares two UUIDs. /// </summary> /// <param name="a">The first UUID to compare.</param> /// <param name="b">The second UUID to compare.</param> /// <returns><c>true</c> if a less than b; otherwise, <c>false</c>.</returns> public static bool operator <(UUID a, UUID b) { return(a.CompareTo(b) < 0); }
public int CompareTo(object obj) { EventID rhs = (EventID)obj; return(s.CompareTo(rhs.s)); }
/// <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 UInt32 @this, UInt32 minValue, UInt32 maxValue) { return(@this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue) <= 0); }
public Boolean runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " ,for " + s_strComponentBeingTested + " ,Source ver " + s_strDtTmVer); String strBaseLoc; try { m_strLoc = "Loc_normalTests"; UInt32 primativeUInt = 100; UInt32 testUIntOne = ((UInt32)primativeUInt); UInt32 testUIntTwo = ((UInt32)2 * primativeUInt); iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to self"; if (testUIntOne.CompareTo(testUIntOne) != 0) { ErrorCode(); } } catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to lesser"; if (testUIntTwo.CompareTo(testUIntOne) < 0) { ErrorCode(); } } catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to lesser"; if (testUIntTwo.CompareTo(testUIntOne) < 0) { ErrorCode(); } } catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("Exception:" + e); Console.WriteLine("testUIntOne = " + testUIntOne); Console.WriteLine("testUIntTwo = " + testUIntTwo); Console.WriteLine("two.CompareTo( one ) = " + testUIntTwo.CompareTo(testUIntOne)); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to greater"; if (testUIntOne.CompareTo(testUIntTwo) > 0) { ErrorCode(); } } catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to greater"; if (testUIntOne.CompareTo(testUIntTwo) > 0) { ErrorCode(); } } catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to String"; testUIntOne.CompareTo("Throw Something"); iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("No Exception thrown"); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } catch (ArgumentException e) {} catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "] -- Wrong Exception!"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to Int16"; testUIntOne.CompareTo(((Int16)12)); iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("No Exception thrown"); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } catch (ArgumentException e) {} catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "] -- Wrong Exception!"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to primative UInt32"; UInt16 pInt = 100; testUIntOne.CompareTo(pInt); iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("No Exception thrown"); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } catch (ArgumentException e) {} catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "] -- Wrong Exception!"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to primative UInt32"; if (testUIntOne.CompareTo(primativeUInt) != 0) { ErrorCode(); } } catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "] -- Wrong Exception!"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } iCountTestcases++; try { m_strLoc = "Starting testcase #" + iCountTestcases; m_strLoc = m_strLoc + "Compare to primative short"; short pShort = 100; testUIntOne.CompareTo(pShort); iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "]"); Console.WriteLine("No Exception thrown"); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } catch (ArgumentException e) {} catch (Exception e) { iCountErrors++; Console.WriteLine("Testcase[" + iCountTestcases + "] -- Wrong Exception!"); Console.WriteLine("Exception:" + e); Console.WriteLine("StrLoc = '" + m_strLoc + "'"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine("Error Err_8888yyy (" + s_strTFAbbrev + ")! Unexpected exception thrown sometime after m_strLoc==" + m_strLoc + " ,exc_general==" + exc_general); } Console.Write(Environment.NewLine); Console.WriteLine("Total Tests Ran: " + iCountTestcases + " Failed Tests: " + iCountErrors); if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " ,BugNums?: " + s_strActiveBugNums); return(false); } }