Browse Source

Bump build now Github should be returned to normal.

af/merge-core
James Jackson-South 7 years ago
parent
commit
5a228ea56d
  1. 47
      tests/ImageSharp.Tests/TestUtilities/TestDataGenerator.cs

47
tests/ImageSharp.Tests/TestUtilities/TestDataGenerator.cs

@ -1,10 +1,24 @@
using System;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
namespace SixLabors.ImageSharp.Tests
{
/// <summary>
/// Helper methods that allow the creation of random test data.
/// </summary>
internal static class TestDataGenerator
{
/// <summary>
/// Creates an <see cref="float[]"/> of the given length consisting of random values between the two ranges.
/// </summary>
/// <param name="rnd">The pseudo-random number generator.</param>
/// <param name="length">The length.</param>
/// <param name="minVal">The minimum value.</param>
/// <param name="maxVal">The maximum value.</param>
/// <returns>The <see cref="float[]"/>.</returns>
public static float[] GenerateRandomFloatArray(this Random rnd, int length, float minVal, float maxVal)
{
float[] values = new float[length];
@ -17,6 +31,14 @@ namespace SixLabors.ImageSharp.Tests
return values;
}
/// <summary>
/// Creates an <see cref="Vector4[]"/> of the given length consisting of random values between the two ranges.
/// </summary>
/// <param name="rnd">The pseudo-random number generator.</param>
/// <param name="length">The length.</param>
/// <param name="minVal">The minimum value.</param>
/// <param name="maxVal">The maximum value.</param>
/// <returns>The <see cref="Vector4[]"/>.</returns>
public static Vector4[] GenerateRandomVectorArray(this Random rnd, int length, float minVal, float maxVal)
{
var values = new Vector4[length];
@ -33,20 +55,32 @@ namespace SixLabors.ImageSharp.Tests
return values;
}
/// <summary>
/// Creates an <see cref="float[]"/> of the given length consisting of rounded random values between the two ranges.
/// </summary>
/// <param name="rnd">The pseudo-random number generator.</param>
/// <param name="length">The length.</param>
/// <param name="minVal">The minimum value.</param>
/// <param name="maxVal">The maximum value.</param>
/// <returns>The <see cref="float[]"/>.</returns>
public static float[] GenerateRandomRoundedFloatArray(this Random rnd, int length, float minVal, float maxVal)
{
float[] values = new float[length];
for (int i = 0; i < length; i++)
{
values[i] = (float) Math.Round(rnd.GetRandomFloat(minVal, maxVal));
values[i] = (float)Math.Round(rnd.GetRandomFloat(minVal, maxVal));
}
return values;
}
/// <summary>
/// Creates an <see cref="byte[]"/> of the given length consisting of random values.
/// </summary>
/// <param name="rnd">The pseudo-random number generator.</param>
/// <param name="length">The length.</param>
/// <returns>The <see cref="byte[]"/>.</returns>
public static byte[] GenerateRandomByteArray(this Random rnd, int length)
{
byte[] values = new byte[length];
@ -54,9 +88,6 @@ namespace SixLabors.ImageSharp.Tests
return values;
}
private static float GetRandomFloat(this Random rnd, float minVal, float maxVal)
{
return (float)rnd.NextDouble() * (maxVal - minVal) + minVal;
}
private static float GetRandomFloat(this Random rnd, float minVal, float maxVal) => ((float)rnd.NextDouble() * (maxVal - minVal)) + minVal;
}
}
Loading…
Cancel
Save