SPRNET-1490 extended support for IsZero to Byte and SByte, improved tests around IsZero, and fixed several poss. casting errors

This commit is contained in:
Steve Bohlen
2012-04-17 15:40:16 -04:00
parent 153a1bb909
commit 9ccfaeb3e2
2 changed files with 47 additions and 16 deletions

View File

@@ -141,15 +141,15 @@ namespace Spring.Util
else if (number is Int64)
return ((Int64)number) == 0;
else if (number is UInt16)
return ((Int32)number) == 0;
return ((UInt16)number) == 0;
else if (number is UInt32)
return ((Int64)number) == 0;
return ((UInt32)number) == 0;
else if (number is UInt64)
return (Convert.ToDecimal(number) == 0);
else if (number is Byte)
return ((Int16)number) == 0;
return ((Byte)number) == 0;
else if (number is SByte)
return ((Int16)number) == 0;
return ((SByte)number) == 0;
else if (number is Single)
return ((Single)number) == 0f;
else if (number is Double)

View File

@@ -65,20 +65,51 @@ namespace Spring.Util
}
[Test]
public void IsNumber()
public void IsNumber()
{
Assert.IsTrue(NumberUtils.IsNumber(10));
Assert.IsTrue(NumberUtils.IsNumber(10L));
Assert.IsTrue(NumberUtils.IsNumber((short) 10));
Assert.IsFalse(NumberUtils.IsNumber('e'));
Assert.IsFalse(NumberUtils.IsNumber(null));
Assert.IsTrue(NumberUtils.IsNumber(9.5D));
Assert.IsTrue(NumberUtils.IsNumber(9.5F));
Assert.IsFalse(NumberUtils.IsNumber(this));
Assert.IsFalse(NumberUtils.IsNumber(null));
Assert.IsFalse(NumberUtils.IsNumber(string.Empty));
Assert.IsTrue(NumberUtils.IsNumber(10));
Assert.IsTrue(NumberUtils.IsNumber(10L));
Assert.IsTrue(NumberUtils.IsNumber((short)10));
Assert.IsFalse(NumberUtils.IsNumber('e'));
Assert.IsFalse(NumberUtils.IsNumber(null));
Assert.IsTrue(NumberUtils.IsNumber(9.5D));
Assert.IsTrue(NumberUtils.IsNumber(9.5F));
Assert.IsFalse(NumberUtils.IsNumber(this));
Assert.IsFalse(NumberUtils.IsNumber(null));
Assert.IsFalse(NumberUtils.IsNumber(string.Empty));
}
[Test]
public void IsZero()
{
Assert.IsFalse(NumberUtils.IsZero((Int16)2));
Assert.IsTrue(NumberUtils.IsZero((Int16)0));
Assert.IsFalse(NumberUtils.IsZero((Int32)2));
Assert.IsTrue(NumberUtils.IsZero((Int32)0));
Assert.IsFalse(NumberUtils.IsZero((Int64)2));
Assert.IsTrue(NumberUtils.IsZero((Int64)0));
Assert.IsFalse(NumberUtils.IsZero((UInt16)2));
Assert.IsTrue(NumberUtils.IsZero((UInt16)0));
Assert.IsFalse(NumberUtils.IsZero((UInt32)2));
Assert.IsTrue(NumberUtils.IsZero((UInt32)0));
Assert.IsFalse(NumberUtils.IsZero((UInt64)2));
Assert.IsTrue(NumberUtils.IsZero((UInt64)0));
Assert.IsFalse(NumberUtils.IsZero((decimal)2));
Assert.IsTrue(NumberUtils.IsZero((decimal)0));
Assert.IsTrue(NumberUtils.IsZero((Byte?)0));
Assert.IsFalse(NumberUtils.IsZero((Byte)2));
Assert.IsTrue(NumberUtils.IsZero((SByte?)0));
Assert.IsFalse(NumberUtils.IsZero((SByte)2));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NegateNull()
@@ -90,7 +121,7 @@ namespace Spring.Util
[ExpectedException(typeof(ArgumentException))]
public void NegateString()
{
NumberUtils.Negate(null);
NumberUtils.Negate(string.Empty);
}
[Test]