@ -5,42 +5,12 @@ namespace SixLabors.ImageSharp.Tests.Common;
public class NumericsTests
public class NumericsTests
{
{
private static readonly int [ ] NormalizeSpanLengthValues =
[
0 ,
1 ,
3 ,
4 ,
5 ,
7 ,
8 ,
9 ,
1 5 ,
1 6 ,
1 7 ,
3 1 ,
3 2 ,
3 3 ,
6 3 ,
6 4 ,
6 5 ,
1 2 7 ,
1 2 8 ,
1 2 9 ,
2 0 4 8
] ;
private ITestOutputHelper Output { get ; }
private ITestOutputHelper Output { get ; }
public NumericsTests ( ITestOutputHelper output ) = > this . Output = output ;
public NumericsTests ( ITestOutputHelper output ) = > this . Output = output ;
public static TheoryData < int > IsOutOfRangeTestData = new ( ) { int . MinValue , - 1 , 0 , 1 , 6 , 7 , 8 , 9 1 , 9 2 , 9 3 , int . MaxValue } ;
public static TheoryData < int > IsOutOfRangeTestData = new ( ) { int . MinValue , - 1 , 0 , 1 , 6 , 7 , 8 , 9 1 , 9 2 , 9 3 , int . MaxValue } ;
/// <summary>
/// Gets lengths that exercise scalar execution and the supported SIMD widths.
/// </summary>
public static TheoryData < int > NormalizeSpanLengths = > new ( NormalizeSpanLengthValues ) ;
private static uint DivideCeil_ReferenceImplementation ( uint value , uint divisor ) = > ( uint ) MathF . Ceiling ( ( float ) value / divisor ) ;
private static uint DivideCeil_ReferenceImplementation ( uint value , uint divisor ) = > ( uint ) MathF . Ceiling ( ( float ) value / divisor ) ;
[Fact]
[Fact]
@ -84,30 +54,4 @@ public class NumericsTests
Assert . True ( expected = = actual , $"IsOutOfRange({value}, {min}, {max})" ) ;
Assert . True ( expected = = actual , $"IsOutOfRange({value}, {min}, {max})" ) ;
}
}
/// <summary>
/// Verifies that normalization divides every element by the supplied sum.
/// </summary>
/// <param name="length">The input length.</param>
[Theory]
[MemberData(nameof(NormalizeSpanLengths))]
public void NormalizeMatchesScalarFormula ( int length )
{
float [ ] actual = new float [ length ] ;
float [ ] expected = new float [ length ] ;
for ( int i = 0 ; i < actual . Length ; i + + )
{
actual [ i ] = ( i + 1 ) * 0.125F ;
expected [ i ] = actual [ i ] / 7.5F ;
}
Numerics . Normalize ( actual , 7.5F ) ;
Assert . Equal ( expected . Length , actual . Length ) ;
for ( int i = 0 ; i < expected . Length ; i + + )
{
Assert . Equal ( BitConverter . SingleToInt32Bits ( expected [ i ] ) , BitConverter . SingleToInt32Bits ( actual [ i ] ) ) ;
}
}
}
}