check aray interface

This commit is contained in:
ikpil 2024-01-21 09:46:20 +09:00 committed by Ikpil
parent 07b50d9391
commit c53162f3e3
1 changed files with 25 additions and 31 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using DotRecast.Core.Collections; using DotRecast.Core.Collections;
using NUnit.Framework; using NUnit.Framework;
@ -7,47 +8,40 @@ namespace DotRecast.Core.Test;
[Parallelizable] [Parallelizable]
public class RcStackArrayTest public class RcStackArrayTest
{ {
[Test] public List<int> RandomValues(int size)
public void TestRcStackArray()
{ {
var rand = new RcRand(); var rand = new RcRand();
// excepted values // excepted values
var list = new List<int>(); var list = new List<int>();
for (int i = 0; i < 1024; ++i) for (int i = 0; i < size; ++i)
{ {
list.Add(rand.NextInt32()); list.Add(rand.NextInt32());
} }
{ return list;
RcStackArray4<int> array = RcStackArray4<int>.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<int> array = RcStackArray8<int>.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]));
}
}
} }
public void Test<T>(T a) [Test]
public void TestRcStackArray4()
{ {
T s = a; var values = RandomValues(4);
RcStackArray4<int> array = RcStackArray4<int>.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<IndexOutOfRangeException>(() => array[-1] = 0);
Assert.Throws<IndexOutOfRangeException>(() => array[array.Length + 1] = 0);
Assert.Throws<IndexOutOfRangeException>(() => _ = array[-1]);
Assert.Throws<IndexOutOfRangeException>(() => _ = array[array.Length + 1]);
} }
} }