public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: GetHashCode should always return the same value for same TimeSpan instance");

        try
        {
            long randValue = TestLibrary.Generator.GetInt64(-55);
            TimeSpan ts = new TimeSpan(randValue);

            int hash1 = ts.GetHashCode();
            int hash2 = ts.GetHashCode();

            if (hash1 != hash2)
            {
                TestLibrary.TestFramework.LogError("001.1", "GetHashCode not always return the same value for same TimeSpan instance");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] hash1 = " + hash1 + ", hash2 = " + hash2 + ", randValue = " + randValue);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Exemple #2
0
 public virtual bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
   TimeSpan	ts1;
   TimeSpan	ts2;
   TimeSpan	tsResult;
   do
     {
     ++iCountTestcases;
     Console.Error.WriteLine( "[]  Negate positive time to yield negative time" );
     try
       {
       ts1 = new TimeSpan(10*TimeSpan.TicksPerHour);
       ts2 = new TimeSpan(10*TimeSpan.TicksPerHour);
       if ( ts1.GetHashCode() != ts2.GetHashCode() )
	 {
	 String strInfo = strTest + " error: ";
	 strInfo = strInfo + "Expected Ticks <" + ts1.GetHashCode() + "> ";
	 strInfo = strInfo + "Returned Ticks <" + ts2.GetHashCode() + "> ";
	 Console.WriteLine( strTest+ "E_101a: " + strInfo );
	 ++iCountErrors;
	 break;
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     }
   while ( false );
   Console.Error.Write( strName );
   Console.Error.Write( ": " );
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
     return true;
     }
   else
     {
     System.String strFailMsg = null;
     Console.WriteLine( strTest+ strPath );
     Console.WriteLine( strTest+ "FAiL" );
     Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
     return false;
     }
   }
 public override int GetHashCode()
 {
     return(dateStart.GetHashCode() ^
            dateEnd.GetHashCode() ^
            daylightDelta.GetHashCode() ^
            daylightTransitionStart.GetHashCode() ^
            daylightTransitionEnd.GetHashCode());
 }
Exemple #4
0
        internal Value(System.TimeSpan value, Parameterization p = Parameterization.Value)
            : base(value)
        {
            Original  = value;
            _clrType  = typeof(System.TimeSpan);
            _hashCode = GetCrossTypeHashCode(_clrType, value.GetHashCode());

            Build = (buildContext, buildArgs) =>
            {
                return((p != Parameterization.None) ? (value.Parameterize(buildContext, p) ?? Mapping.BuildCast(value)) : Mapping.BuildCast(value));
            };
        }
 static int GetHashCode(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.TimeSpan obj = (System.TimeSpan)ToLua.CheckObject(L, 1, typeof(System.TimeSpan));
         int             o   = obj.GetHashCode();
         LuaDLL.lua_pushinteger(L, o);
         ToLua.SetBack(L, 1, obj);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #6
0
    public static void TestEquals(TimeSpan timeSpan1, object obj, bool expected)
    {
        if (obj is TimeSpan)
        {
            TimeSpan timeSpan2 = (TimeSpan)obj;
            Assert.Equal(expected, TimeSpan.Equals(timeSpan1, timeSpan2));
            Assert.Equal(expected, timeSpan1.Equals(timeSpan2));
            Assert.Equal(expected, timeSpan1 == timeSpan2);
            Assert.Equal(!expected, timeSpan1 != timeSpan2);

            Assert.Equal(expected, timeSpan1.GetHashCode().Equals(timeSpan2.GetHashCode()));
        }
        Assert.Equal(expected, timeSpan1.Equals(obj));
    }
Exemple #7
0
 public override int GetHashCode()
 {
     return(dt.GetHashCode() ^ utc_offset.GetHashCode());
 }
Exemple #8
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(_timeSpan.GetHashCode());
 }
		public MFTestResults GetHashCode_Test5(  )
		{
            /// <summary>
            /// 1. Test that GetHashCode returns the same for the same TimeSpan
            /// 2. Test that GetHashCode returns differently for different TimeSpans
            /// </summary>
            ///
            Log.Comment("Testing the GetHashCode method");
			bool testResult = true;
            Random random = new Random();
            Log.Comment("Test that GetHashCode returns the same for the same TimeSpan");
			for( int i = 0; i<30; i++ )
			{
				int hours = random.Next(23);
				int minutes = random.Next(59);
				int seconds = random.Next(59);
				TimeSpan ts01 = new TimeSpan( hours, minutes, seconds );
				TimeSpan ts02 = new TimeSpan( hours, minutes, seconds );
				Log.Comment( ts01.GetHashCode().ToString() + " == " + 
                    ts02.GetHashCode().ToString() );
				testResult &= (ts01.GetHashCode() == ts02.GetHashCode());
			}

			TimeSpan ts1 = new TimeSpan( 1,1,1 );
            Log.Comment("Test that GetHashCode returns differently for different TimeSpans");
            Log.Comment("This may fail erroneously.");  
            Log.Comment("From the docs two different TimeSpans may have same hashcode" );
			Log.Comment( "But, for the most part the values should be different." );
			for( int i = 0; i < 5; i++ )
			{
				TimeSpan ts2 = new TimeSpan( random.Next(23),
                    random.Next(59),random.Next(59) );
				Log.Comment( ts1.GetHashCode().ToString() + " Does Not Equal " + 
                    ts2.GetHashCode().ToString() );
				if( ts1 != ts2 )
					testResult &= (ts1.GetHashCode() != ts2.GetHashCode());
				else
					testResult &= (ts1.GetHashCode() == ts2.GetHashCode());
			}

			return (testResult? MFTestResults.Pass: MFTestResults.Fail);
		}
Exemple #10
0
 /// <summary>
 /// Returns the hash code for this instance.
 /// </summary>
 /// <returns>
 /// A 32-bit signed integer that is the hash code for this instance.
 /// </returns>
 public override int GetHashCode() => core.GetHashCode();
Exemple #11
0
 public override int GetHashCode()
 {
     return(mTicks.GetHashCode());
 }
Exemple #12
0
 public override int GetHashCode()
 {
     System.TimeSpan ts = new System.TimeSpan(m_ticks);
     return(ts.GetHashCode());
 }
Exemple #13
0
 public override int GetHashCode()
 {
     return(years.GetHashCode() ^ months.GetHashCode() ^ myValue.GetHashCode());
 }