NUnit.Framework.EqualityAsserter.IsNumericType(object)

Here are the examples of the csharp api NUnit.Framework.EqualityAsserter.IsNumericType(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : EqualityAsserter.cs
with MIT License
from inthehand

protected virtual bool ObjectsEqual( Object expected, Object actual )
		{
			if ( expected == null && actual == null ) return true;
			if ( expected == null || actual == null ) return false;

			//if ( expected.GetType().IsArray && actual.GetType().IsArray )
			//	return ArraysEqual( (System.Array)expected, (System.Array)actual );

			if ( expected is double && actual is double )
			{
				if ( double.IsNaN((double)expected) && double.IsNaN((double)actual) )
					return true;
				// handle infinity specially since subtracting two infinite values gives 
				// NaN and the following test fails. mono also needs NaN to be handled
				// specially although ms.net could use either method.
				if (double.IsInfinity((double)expected) || double.IsNaN((double)expected) || double.IsNaN((double)actual))
					return expected.Equals( actual );
				else 
					return Math.Abs((double)expected-(double)actual) <= this.delta;
			}

			//			if ( expected is float && actual is float )
			//			{
			//				// handle infinity specially since subtracting two infinite values gives 
			//				// NaN and the following test fails. mono also needs NaN to be handled
			//				// specially although ms.net could use either method.
			//				if (float.IsInfinity((float)expected) || float.IsNaN((float)expected) || float.IsNaN((float)actual))
			//					return (float)expected == (float)actual;
			//				else 
			//					return Math.Abs((float)expected-(float)actual) <= (float)this.delta;
			//			}

			if ( expected.GetType() != actual.GetType() &&
				IsNumericType( expected )  && IsNumericType( actual ) )
			{
				//
				// Convert to strings and compare result to avoid
				// issues with different types that have the same
				// value
				//
				string sExpected = expected.ToString();
				string sActual   = actual.ToString();
				return sExpected.Equals( sActual );
			}
			return expected.Equals(actual);
		}