diff --git a/test/DotRecast.Core.Test/RcStackArrayTest.cs b/test/DotRecast.Core.Test/RcStackArrayTest.cs index 37bde51..24a8d4e 100644 --- a/test/DotRecast.Core.Test/RcStackArrayTest.cs +++ b/test/DotRecast.Core.Test/RcStackArrayTest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using DotRecast.Core.Collections; using NUnit.Framework; @@ -7,47 +8,40 @@ namespace DotRecast.Core.Test; [Parallelizable] public class RcStackArrayTest { - [Test] - public void TestRcStackArray() + public List RandomValues(int size) { var rand = new RcRand(); // excepted values var list = new List(); - for (int i = 0; i < 1024; ++i) + for (int i = 0; i < size; ++i) { list.Add(rand.NextInt32()); } - { - RcStackArray4 array = RcStackArray4.Empty; - for (int i = 0; i < array.Length; ++i) - { - array[i] = list[i]; - } - - for (int i = 0; i < array.Length; ++i) - { - Assert.That(array[i], Is.EqualTo(list[i])); - } - } - - { - RcStackArray8 array = RcStackArray8.Empty; - for (int i = 0; i < array.Length; ++i) - { - array[i] = list[i]; - } - - for (int i = 0; i < array.Length; ++i) - { - Assert.That(array[i], Is.EqualTo(list[i])); - } - } + return list; } - public void Test(T a) + [Test] + public void TestRcStackArray4() { - T s = a; + var values = RandomValues(4); + RcStackArray4 array = RcStackArray4.Empty; + for (int i = 0; i < array.Length; ++i) + { + array[i] = values[i]; + } + + for (int i = 0; i < array.Length; ++i) + { + Assert.That(array[i], Is.EqualTo(values[i])); + } + + Assert.That(array[^1], Is.EqualTo(values[^1])); + + Assert.Throws(() => array[-1] = 0); + Assert.Throws(() => array[array.Length + 1] = 0); + Assert.Throws(() => _ = array[-1]); + Assert.Throws(() => _ = array[array.Length + 1]); } } \ No newline at end of file