From c53162f3e30492a67d5a4c320a74034cd2b87748 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 21 Jan 2024 09:46:20 +0900 Subject: [PATCH] check aray interface --- test/DotRecast.Core.Test/RcStackArrayTest.cs | 56 +++++++++----------- 1 file changed, 25 insertions(+), 31 deletions(-) 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