Add test utils
This commit is contained in:
parent
8d518f4e54
commit
ffd0882ce7
4 changed files with 105 additions and 0 deletions
16
src/Ryujinx.Tests/EnumerableTheoryData.cs
Normal file
16
src/Ryujinx.Tests/EnumerableTheoryData.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
src/Ryujinx.Tests/RandomUtils.cs
Normal file
53
src/Ryujinx.Tests/RandomUtils.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
16
src/Ryujinx.Tests/RangeTheoryData.cs
Normal file
16
src/Ryujinx.Tests/RangeTheoryData.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
src/Ryujinx.Tests/RangeUtils.cs
Normal file
20
src/Ryujinx.Tests/RangeUtils.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue