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