Skip to content

Commit

Permalink
check aray interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Jan 21, 2024
1 parent 07b50d9 commit c53162f
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions test/DotRecast.Core.Test/RcStackArrayTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using DotRecast.Core.Collections;
using NUnit.Framework;

Expand All @@ -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)
{
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]));
}
array[i] = values[i];
}

for (int i = 0; i < array.Length; ++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]));
}
Assert.That(array[i], Is.EqualTo(values[i]));
}
}

public void Test<T>(T a)
{
T s = a;
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]);
}
}

0 comments on commit c53162f

Please sign in to comment.