mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-13 11:41:44 +00:00
Add additional tests
Added index out of range tests for when setting elements and for object or struct arrays.
This commit is contained in:
parent
2757ebec11
commit
68917ff2ef
1 changed files with 111 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
using Cosmos.TestRunner;
|
||||
|
||||
|
|
@ -56,30 +56,122 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
Assert.IsTrue(xDoubleResult[3] == xDoubleExpectedResult[3], "Assinging values to double array elements doesn't work: xResult[1] = " + (uint)xDoubleResult[3] + " != " + (uint)xDoubleExpectedResult[3]);
|
||||
|
||||
//Test array indexes
|
||||
int y = 0;
|
||||
int[] x = new int[5] { 1, 2, 3, 4, 5 };
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
y = x[1];
|
||||
y = x[7];
|
||||
int y = 0;
|
||||
int[] x = new int[5] { 1, 2, 3, 4, 5 };
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
y = x[1];
|
||||
y = x[7];
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error && y == 2, "Index out of range exception works correctly for too large positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
#pragma warning disable CS0251 // Indexing an array with a negative index
|
||||
y = x[-1];
|
||||
#pragma warning restore CS0251 // Indexing an array with a negative index
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error && y == 2, "Index out of range exception works correctly for too small positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x[7] = 9;
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly when setting elements.");
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
object y;
|
||||
object[] x = new object[5] { new object(), new object(), new object(), new object(), new object() };
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
y = x[28987];
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly for too large positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
#pragma warning disable CS0251 // Indexing an array with a negative index
|
||||
y = x[-1];
|
||||
#pragma warning restore CS0251 // Indexing an array with a negative index
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly for too small positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x[7] = new object();
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly when setting elements.");
|
||||
}
|
||||
Assert.IsTrue(error && y == 2, "Index out of range exception works correctly for too large positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
y = x[-1];
|
||||
Test y;
|
||||
Test[] x = new Test[5] { new Test(), new Test(), new Test(), new Test(), new Test() };
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
y = x[28987];
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly for too large positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
#pragma warning disable CS0251 // Indexing an array with a negative index
|
||||
y = x[-1];
|
||||
#pragma warning restore CS0251 // Indexing an array with a negative index
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly for too small positions.");
|
||||
error = false;
|
||||
try
|
||||
{
|
||||
x[7] = new Test();
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error, "Index out of range exception works correctly when setting elements.");
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
Assert.IsTrue(error && y == 2, "Index out of range exception works correctly for too small positions.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct Test
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue