From 80b6da11a719fc21494e8305c11e6b4fc0436ef6 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 8 Jul 2023 23:48:24 +0200 Subject: [PATCH] Fix issues with Range classes & Add StaticTheoryData --- src/Ryujinx.Tests/RangeTheoryData.cs | 2 +- src/Ryujinx.Tests/RangeUtils.cs | 6 +-- src/Ryujinx.Tests/StaticTheoryData.cs | 58 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/Ryujinx.Tests/StaticTheoryData.cs diff --git a/src/Ryujinx.Tests/RangeTheoryData.cs b/src/Ryujinx.Tests/RangeTheoryData.cs index 0299468ba..d07883a74 100644 --- a/src/Ryujinx.Tests/RangeTheoryData.cs +++ b/src/Ryujinx.Tests/RangeTheoryData.cs @@ -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); } diff --git a/src/Ryujinx.Tests/RangeUtils.cs b/src/Ryujinx.Tests/RangeUtils.cs index 94a711a11..0e415ab38 100644 --- a/src/Ryujinx.Tests/RangeUtils.cs +++ b/src/Ryujinx.Tests/RangeUtils.cs @@ -5,16 +5,16 @@ namespace Ryujinx.Tests { public static class RangeUtils { - public static IEnumerable RangeData(T from, T to, T step) where T : INumber + public static List RangeData(T from, T to, T step) where T : INumber { List 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; } } } diff --git a/src/Ryujinx.Tests/StaticTheoryData.cs b/src/Ryujinx.Tests/StaticTheoryData.cs new file mode 100644 index 000000000..b38d3dc88 --- /dev/null +++ b/src/Ryujinx.Tests/StaticTheoryData.cs @@ -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 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); + } + } + } +}