mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-08 20:02:39 +00:00
Fix issues with Range classes & Add StaticTheoryData
This commit is contained in:
parent
2c884075ca
commit
80b6da11a7
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
58
src/Ryujinx.Tests/StaticTheoryData.cs
Normal file
58
src/Ryujinx.Tests/StaticTheoryData.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue