mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 13:28:41 +00:00
Added tests for checked conversions
This commit is contained in:
parent
580b09feee
commit
086454cdfb
8 changed files with 380 additions and 9 deletions
|
|
@ -127,13 +127,72 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((ulong)minValue == 0x0000000000000000, "Conv_U8 for Byte doesn't work");
|
||||
|
||||
// Test Conv_R4
|
||||
Assert.IsTrue((float)maxValue == Byte.MaxValue, "Conv_R4 for Byte doesn't work" + (float)maxValue);
|
||||
Assert.IsTrue((float)maxValue == Byte.MaxValue, "Conv_R4 for Byte doesn't work");
|
||||
Assert.IsTrue((float)minValue == Byte.MinValue, "Conv_R4 for Byte doesn't work");
|
||||
|
||||
// Test Conv_R8
|
||||
Assert.IsTrue((double)maxValue == Byte.MaxValue, "Conv_R8 for Byte doesn't work");
|
||||
Assert.IsTrue((double)minValue == Byte.MinValue, "Conv_R8 for Byte doesn't work");
|
||||
|
||||
// Test checked conversions to bytes
|
||||
int val = 1;
|
||||
int test = 125;
|
||||
// Test Conv_Ovf_U1
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((byte)test == 0x7D, "Conv_Ovf_U1 for Byte doesn't work(throws incorrectly)");
|
||||
byte x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (byte)(val + 255);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U1 for Byte doesn't work(error was not thrown)");
|
||||
Assert.IsTrue((byte)(long)125 == 0x7D, "Conv_Ovf_U1 for long to Byte doesn't work(throws incorrectly)");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (byte)(val + 0x8_0000_0000);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U1 for from positive Long to Byte doesn't work(error was not thrown)");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (byte)(val + -0x8_0000_0001);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U1 for from negative Long to Byte doesn't work(error was not thrown)");
|
||||
}
|
||||
|
||||
|
||||
// Test Conv_Ovf_U1_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((byte)(uint)125 == 0x7D, "Conv_Ovf_U1_Un for Byte doesn't work(throws incorrectly)");
|
||||
byte x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (byte)(uint)(val + 300);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U1_Un for Byte doesn't work(error was not thrown): ");
|
||||
}
|
||||
|
||||
// Test Methods
|
||||
val2 = TestMethod(value);
|
||||
Assert.IsTrue(value == 60, "Passing a Byte as a method parameter doesn't work");
|
||||
|
|
|
|||
|
|
@ -135,6 +135,66 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((double)maxValue == Int16.MaxValue, "Conv_R8 for Int16 doesn't work");
|
||||
Assert.IsTrue((double)minValue == Int16.MinValue, "Conv_R8 for Int16 doesn't work");
|
||||
|
||||
//Test checked conversions
|
||||
int val = 1;
|
||||
long test = 125;
|
||||
|
||||
// Test Conv_Ovf_I2
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((short)val == 1, "Conv_Ovf_I2 doesn't work(throws incorrectly)");
|
||||
short x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (short)(val + short.MaxValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I2 doesn't work(error was not thrown): " + x);
|
||||
Assert.IsTrue((short)test == 0x7D, "Conv_Ovf_I2 for long to short doesn't work(throws incorrectly)");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (short)(val + 0x8_0000_0000);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I2 for from positive long to short doesn't work(error was not thrown): " + x);
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (short)(val + -0x8_0000_0001);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I2 for from negative long to short doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
|
||||
// Test Conv_Ovf_I2_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((short)(uint)125 == 0x7D, "Conv_Ovf_I2_Un doesn't work(throws incorrectly)");
|
||||
short x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (short)(uint)(val + short.MaxValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I2_Un doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
// Test Methods
|
||||
val2 = TestMethod(value);
|
||||
Assert.IsTrue(value == 60, "Passing an Int16 as a method parameter doesn't work");
|
||||
|
|
|
|||
|
|
@ -135,6 +135,56 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((double)maxValue == Int32.MaxValue, "Conv_R8 for Int32 doesn't work");
|
||||
Assert.IsTrue((double)minValue == Int32.MinValue, "Conv_R8 for Int32 doesn't work");
|
||||
|
||||
//Test checked conversions
|
||||
long val = 1;
|
||||
long test = 125;
|
||||
// Test Conv_Ovf_I4
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((int)test == 0x7D, "Conv_Ovf_I4 doesn't work(throws incorrectly)");
|
||||
Assert.IsTrue((int)(test - 1) == 124, "Conv_Ovf_I4 doesn't work(throws incorrectly)");
|
||||
Assert.IsTrue((int)val == 1, "Conv_Ovf_I4 doesn't work(throws incorrectly)");
|
||||
Assert.IsTrue((int)(2 * val) == 2, "Conv_Ovf_I4 doesn't work(throws incorrectly)");
|
||||
long x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (int)(val + int.MaxValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I4 doesn't work(error was not thrown): " + x);
|
||||
try
|
||||
{
|
||||
x = (int)(val + int.MinValue - 2);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I4 doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
|
||||
// Test Conv_Ovf_I4_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((int)(uint)test == 0x7D, "Conv_Ovf_I4_Un doesn't work(throws incorrectly)");
|
||||
int x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (int)(uint)(val + int.MaxValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I4_Un doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
// Test Methods
|
||||
val2 = TestMethod(value);
|
||||
Assert.IsTrue(value == 60, "Passing an Int32 as a method parameter doesn't work");
|
||||
|
|
@ -173,7 +223,6 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
efuse = true;
|
||||
}
|
||||
Assert.IsTrue(efuse, "Sub_Ovf for Int32 doesn't work: " + val3o);
|
||||
Console.WriteLine("Finished Int32 Tests!");
|
||||
}
|
||||
|
||||
public static int TestMethod(int aParam)
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
string result;
|
||||
string expectedResult;
|
||||
|
||||
value = Int64.MaxValue;
|
||||
value = long.MaxValue;
|
||||
|
||||
result = value.ToString();
|
||||
expectedResult = "9223372036854775807";
|
||||
|
||||
Assert.IsTrue((result == expectedResult), "Int64.ToString doesn't work");
|
||||
|
||||
// Now let's try to concat to a String using '+' operator
|
||||
|
|
@ -178,6 +177,27 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((double)maxValue == Int64.MaxValue, "Conv_R8 for Int64 doesn't work");
|
||||
Assert.IsTrue((double)minValue == Int64.MinValue, "Conv_R8 for Int64 doesn't work");
|
||||
|
||||
//Test checked conversions
|
||||
long val = 1;
|
||||
|
||||
// Test Conv_Ovf_I8_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((long)(ulong)125 == 0x7D, "Conv_Ovf_I8_Un doesn't work(throws incorrectly)");
|
||||
long x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (long)((ulong)val + ulong.MaxValue - 1);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I8_Un doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
|
||||
// Test Methods
|
||||
|
||||
value = 60;
|
||||
|
|
|
|||
|
|
@ -137,6 +137,64 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((double)maxValue == SByte.MaxValue, "Conv_R8 for SByte doesn't work");
|
||||
Assert.IsTrue((double)minValue == SByte.MinValue, "Conv_R8 for SByte doesn't work");
|
||||
|
||||
//Now test checked conversions
|
||||
int val = 1;
|
||||
int test = 125;
|
||||
|
||||
// Test Conv_Ovf_I1
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((sbyte)test == 0x7D, "Conv_Ovf_I1 for SByte doesn't work(throws incorrectly)");
|
||||
sbyte x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (sbyte)(val + 127);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I1 for SByte doesn't work(error was not thrown)");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (sbyte)(val + 0x8_0000_0000);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I1 for from positive Long to SByte doesn't work(error was not thrown)");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (sbyte)(val + -0x8_0000_0001);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I1 for from negative Long to SByte doesn't work(error was not thrown)");
|
||||
}
|
||||
|
||||
// Test Conv_Ovf_I1_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((sbyte)(uint)125 == 0x7D, "Conv_Ovf_I1_Un for SByte doesn't work(throws incorrectly)");
|
||||
sbyte x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (sbyte)(uint)(val + 127);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_I1_Un for SByte doesn't work(error was not thrown)");
|
||||
}
|
||||
|
||||
// Test Methods
|
||||
val2 = TestMethod(value);
|
||||
Assert.IsTrue(value == 60, "Passing an SByte as a method parameter doesn't work");
|
||||
|
|
|
|||
|
|
@ -134,6 +134,66 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((double)maxValue == UInt16.MaxValue, "Conv_R8 for UInt16 doesn't work");
|
||||
Assert.IsTrue((double)minValue == UInt16.MinValue, "Conv_R8 for UInt16 doesn't work");
|
||||
|
||||
//Test checked conversions
|
||||
int val = 1;
|
||||
int test = 125;
|
||||
|
||||
// Test Conv_Ovf_U2
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((ushort)test == 0x7D, "Conv_Ovf_U2 doesn't work(throws incorrectly)");
|
||||
ushort x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (ushort)(ushort.MaxValue + val);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U2 doesn't work(error was not thrown): " + x);
|
||||
Assert.IsTrue((uint)(long)125 == 0x7D, "Conv_Ovf_U2 for long to ushort doesn't work(throws incorrectly)");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (ushort)(val + 0x8_0000_0000);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U2 for from positive long to ushort doesn't work(error was not thrown): " + x);
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x = (ushort)(val + -0x8_0000_0001);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U2 for from negative long to ushort doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
|
||||
// Test Conv_Ovf_U2_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((ushort)(uint)125 == 0x7D, "Conv_Ovf_U2_Un doesn't work(throws incorrectly)");
|
||||
ushort x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (ushort)(uint)(val + ushort.MaxValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U2_Un doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
// Test Methods
|
||||
val2 = TestMethod(value);
|
||||
Assert.IsTrue(value == 60, "Passing an UInt16 as a method parameter doesn't work");
|
||||
|
|
|
|||
|
|
@ -127,14 +127,64 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((ulong)minValue == 0x0000000000000000, "Conv_U8 for UInt32 doesn't work");
|
||||
|
||||
// Test Conv_R4
|
||||
Assert.IsTrue((float)maxValue == UInt32.MaxValue, "Conv_R4 for UInt32 doesn't work");
|
||||
Assert.IsTrue((float)minValue == UInt32.MinValue, "Conv_R4 for UInt32 doesn't work");
|
||||
Assert.IsTrue((float)maxValue == uint.MaxValue, "Conv_R4 for UInt32 doesn't work");
|
||||
Assert.IsTrue((float)minValue == uint.MinValue, "Conv_R4 for UInt32 doesn't work");
|
||||
|
||||
// Test Conv_R8
|
||||
Assert.IsTrue((double)maxValue == UInt32.MaxValue, "Conv_R8 for UInt32 doesn't work");
|
||||
Assert.IsTrue((double)minValue == UInt32.MinValue, "Conv_R8 for UInt32 doesn't work");
|
||||
Assert.IsTrue((double)maxValue == uint.MaxValue, "Conv_R8 for UInt32 doesn't work");
|
||||
Assert.IsTrue((double)minValue == uint.MinValue, "Conv_R8 for UInt32 doesn't work");
|
||||
|
||||
// Test Methods
|
||||
//Test checked conversions
|
||||
long val = 1;
|
||||
|
||||
// Test Conv_Ovf_U4
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((uint)(long)125 == 0x7D, "Conv_Ovf_U4 doesn't work(throws incorrectly)");
|
||||
uint x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (uint)(uint.MaxValue + val);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U4 doesn't work(error was not thrown): " + x);
|
||||
try
|
||||
{
|
||||
int y = 1;
|
||||
x = (uint)(-80 + y);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U4 doesn't work for negative integers(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
|
||||
// Test Conv_Ovf_U4_Un
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((uint)(ulong)125 == 0x7D, "Conv_Ovf_U4_Un doesn't work(throws incorrectly)");
|
||||
long max = uint.MaxValue;
|
||||
Assert.IsTrue((uint)(ulong)max == uint.MaxValue, "Conv_Ovf_U4_Un doesn't work(throws incorrectly)");
|
||||
uint x = 0;
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
x = (uint)(ulong)(val + uint.MaxValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Conv_Ovf_U4_Un doesn't work(error was not thrown): " + x);
|
||||
}
|
||||
|
||||
//Test Methods
|
||||
val2 = TestMethod(value);
|
||||
Assert.IsTrue(value == 60, "Passing an UInt32 as a method parameter doesn't work");
|
||||
Assert.IsTrue(val2 == 61, "Returning an UInt32 value from a method doesn't work");
|
||||
|
|
|
|||
|
|
@ -159,6 +159,21 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue((double)maxValue == UInt64.MaxValue, "Conv_R8 for UInt64 doesn't work");
|
||||
Assert.IsTrue((double)minValue == UInt64.MinValue, "Conv_R8 for UInt64 doesn't work");
|
||||
|
||||
//Test checked conversions
|
||||
|
||||
// Test for Conv_Ovf_U8
|
||||
checked
|
||||
{
|
||||
Assert.IsTrue((ulong)125 == 0x7D, "Conv_Ovf_U8 doesn't work(throws incorrectly)");
|
||||
}
|
||||
|
||||
checked
|
||||
{
|
||||
uint t = 125;
|
||||
Assert.IsTrue((ulong)t == 0x7D, "Conv_Ovf_U8 doesn't work(throws incorrectly)");
|
||||
}
|
||||
// TODO: If possible, somehow add tests for Conv_Ovf_I8_Un
|
||||
|
||||
// Test Methods
|
||||
|
||||
value = 60;
|
||||
|
|
|
|||
Loading…
Reference in a new issue