Fix issues with Range classes & Add StaticTheoryData

This commit is contained in:
TSR Berry 2023-07-08 23:48:24 +02:00
parent 2c884075ca
commit 80b6da11a7
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
3 changed files with 62 additions and 4 deletions

View file

@ -7,7 +7,7 @@ namespace Ryujinx.Tests
{
public RangeTheoryData(T from, T to, T step)
{
for (T i = from; i < to; i += step)
for (T i = from; i <= to; i += step)
{
Add(i);
}

View file

@ -5,16 +5,16 @@ namespace Ryujinx.Tests
{
public static class RangeUtils
{
public static IEnumerable<T> RangeData<T>(T from, T to, T step) where T : INumber<T>
public static List<T> RangeData<T>(T from, T to, T step) where T : INumber<T>
{
List<T> data = new();
for (T i = from; i < to; i += step)
for (T i = from; i <= to; i += step)
{
data.Add(i);
}
return data.AsReadOnly();
return data;
}
}
}

View file

@ -0,0 +1,58 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Xunit;
namespace Ryujinx.Tests
{
public class StaticTheoryData : TheoryData
{
public StaticTheoryData(params object[] data)
{
List<int> indices = new();
int length = -1;
for (int i = 0; i < data.Length; i++)
{
if (data[i] is IList { Count: > 0 } list)
{
indices.Add(i);
if (length == -1)
{
length = list.Count;
}
else if (length != list.Count)
{
throw new NotImplementedException($"{nameof(StaticTheoryData)} currently only works with lists of the same size. (expected: {length}, actual: {list.Count})");
}
}
}
if (indices.Count == 0)
{
AddRow(data);
return;
}
for (int i = 0; i < length; i++)
{
object[] row = new object[data.Length];
for (int j = 0; j < data.Length; j++)
{
if (indices.Contains(j) && data[j] is IList list)
{
row[j] = list[i];
}
else
{
row[j] = data[j];
}
}
AddRow(row);
}
}
}
}