Add test utils

This commit is contained in:
TSR Berry 2023-07-08 20:21:54 +02:00
commit ffd0882ce7
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
4 changed files with 105 additions and 0 deletions

View file

@ -0,0 +1,16 @@
using System.Collections.Generic;
using Xunit;
namespace Ryujinx.Tests
{
public class EnumerableTheoryData<T> : TheoryData<T>
{
public EnumerableTheoryData(IEnumerable<T> data)
{
foreach (T item in data)
{
Add(item);
}
}
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
namespace Ryujinx.Tests
{
public static class RandomUtils
{
public static bool NextBool(this Random random)
{
return random.Next(2) == 1;
}
public static uint NextUShort(this Random random)
{
return (uint)random.Next(ushort.MaxValue);
}
public static uint NextUInt(this Random random)
{
return (uint)random.NextInt64(uint.MaxValue);
}
public static uint NextUInt(this Random random, uint to)
{
return (uint)random.NextInt64(to);
}
public static ulong NextULong(this Random random)
{
byte[] buffer = new byte[8];
random.NextBytes(buffer);
return BitConverter.ToUInt64(buffer);
}
public static byte NextByte(this Random random, byte from, byte to)
{
return (byte)random.Next(from, to);
}
public static IEnumerable<uint> NextUIntEnumerable(this Random random, int count)
{
List<uint> list = new();
for (int i = 0; i < count; i++)
{
list.Add(random.NextUInt());
}
return list.AsReadOnly();
}
}
}

View file

@ -0,0 +1,16 @@
using System.Numerics;
using Xunit;
namespace Ryujinx.Tests
{
public class RangeTheoryData<T> : TheoryData<T> where T : INumber<T>
{
public RangeTheoryData(T from, T to, T step)
{
for (T i = from; i < to; i += step)
{
Add(i);
}
}
}
}

View file

@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Numerics;
namespace Ryujinx.Tests
{
public static class RangeUtils
{
public static IEnumerable<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)
{
data.Add(i);
}
return data.AsReadOnly();
}
}
}