fix: random size of an array for testing could be 0

This commit is contained in:
ikpil 2024-01-21 19:53:00 +09:00 committed by Ikpil
parent 0d4344dabb
commit 96e8b12772
1 changed files with 3 additions and 3 deletions

View File

@ -29,7 +29,7 @@ public class RcRentedArrayTest
{ {
RcRentedArray<int> rentedArray; RcRentedArray<int> rentedArray;
{ {
int length = (int)(rand.Next() * 2048); int length = Math.Max(2, (int)(rand.Next() * 2048));
var values = RandomValues(length); var values = RandomValues(length);
using var array = RcRentedArray.RentDisposableArray<int>(length); using var array = RcRentedArray.RentDisposableArray<int>(length);
@ -44,12 +44,12 @@ public class RcRentedArrayTest
} }
Assert.That(array[^1], Is.EqualTo(values[^1])); Assert.That(array[^1], Is.EqualTo(values[^1]));
Assert.Throws<IndexOutOfRangeException>(() => array[-1] = 0); Assert.Throws<IndexOutOfRangeException>(() => array[-1] = 0);
Assert.Throws<IndexOutOfRangeException>(() => array[array.Length + 1] = 0); Assert.Throws<IndexOutOfRangeException>(() => array[array.Length + 1] = 0);
Assert.Throws<IndexOutOfRangeException>(() => _ = array[-1]); Assert.Throws<IndexOutOfRangeException>(() => _ = array[-1]);
Assert.Throws<IndexOutOfRangeException>(() => _ = array[array.Length + 1]); Assert.Throws<IndexOutOfRangeException>(() => _ = array[array.Length + 1]);
// danger // danger
rentedArray = array; rentedArray = array;
} }