Skip to content

Commit

Permalink
Merge pull request CosmosOS#1165 from quajak/indextests
Browse files Browse the repository at this point in the history
Add tests for IndexOutOfRange exceptions
  • Loading branch information
charlesbetros authored Jun 30, 2019
2 parents eecfcd8 + 42aacad commit 5b671b9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Tests/Kernels/Cosmos.Compiler.Tests.Bcl/System/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ public static void Execute()
xDoubleResult[3] = xDoubleSource[0];

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];
}
catch (IndexOutOfRangeException)
{
error = true;
}
Assert.IsTrue(error && y == 2, "Index out of range exception works correctly for too large positions.");
error = false;
try
{
y = x[-1];
}
catch (IndexOutOfRangeException)
{
error = true;
}
Assert.IsTrue(error && y == 2, "Index out of range exception works correctly for too small positions.");

}
}
}

0 comments on commit 5b671b9

Please sign in to comment.