Browse Source

Update tests

pull/382/head
James Jackson-South 8 years ago
parent
commit
94e95c63d7
  1. 2
      tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs
  2. 6
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  3. 6
      tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
  5. 6
      tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs
  6. 123
      tests/ImageSharp.Tests/Helpers/MathFTests.cs
  7. 4
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

2
tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General
for (int i = 0; i < Block8x8F.Size; i++)
{
ref float v = ref Unsafe.Add(ref b, i);
v = MathF.Round(v);
v = (float)Math.Round(v);
}
}

6
tests/ImageSharp.Benchmarks/Samplers/Glow.cs

@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Benchmarks
int endX = sourceRectangle.Right;
TPixel glowColor = this.GlowColor;
Vector2 centre = Rectangle.Center(sourceRectangle);
float maxDistance = this.Radius > 0 ? MathF.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F;
float maxDistance = this.Radius > 0 ? Math.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F;
// Align start/end positions.
int minX = Math.Max(0, startX);
@ -136,13 +136,13 @@ namespace SixLabors.ImageSharp.Benchmarks
amount = amount.Clamp(0, 1);
// Santize on zero alpha
if (MathF.Abs(backdrop.W) < Constants.Epsilon)
if (Math.Abs(backdrop.W) < Constants.Epsilon)
{
source.W *= amount;
return source;
}
if (MathF.Abs(source.W) < Constants.Epsilon)
if (Math.Abs(source.W) < Constants.Epsilon)
{
return backdrop;
}

6
tests/ImageSharp.Tests/Common/SimdUtilsTests.cs

@ -22,9 +22,9 @@ namespace SixLabors.ImageSharp.Tests.Common
this.Output = output;
}
private static int R(float f) => (int)MathF.Round(f, MidpointRounding.AwayFromZero);
private static int R(float f) => (int)Math.Round(f, MidpointRounding.AwayFromZero);
private static int Re(float f) => (int)MathF.Round(f, MidpointRounding.ToEven);
private static int Re(float f) => (int)Math.Round(f, MidpointRounding.ToEven);
// TODO: Move this to a proper test class!
[Theory]
@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Tests.Common
Assert.Equal(expected, dest);
}
private static float Clamp255(float x) => MathF.Min(255f, MathF.Max(0f, x));
private static float Clamp255(float x) => Math.Min(255f, Math.Max(0f, x));
[Theory]
[InlineData(1, 0)]

2
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs

@ -335,7 +335,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
for (int i = 0; i < 64; i++)
{
float expected = MathF.Round(s[i]);
float expected = (float)Math.Round(s[i]);
float actual = d[i];
Assert.Equal(expected, actual);

6
tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs

@ -236,11 +236,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
float cr = values.Component2[i] - 128F;
float k = values.Component3[i] / 255F;
v.X = (255F - MathF.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k;
v.Y = (255F - MathF.Round(
v.X = (255F - (float)Math.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k;
v.Y = (255F - (float)Math.Round(
y - (0.344136F * cb) - (0.714136F * cr),
MidpointRounding.AwayFromZero)) * k;
v.Z = (255F - MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k;
v.Z = (255F - (float)Math.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k;
v.W = 1F;
v *= scale;

123
tests/ImageSharp.Tests/Helpers/MathFTests.cs

@ -1,123 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Helpers
{
public class MathFTests
{
[Fact]
public void MathF_PI_Is_Equal()
{
Assert.Equal(MathF.PI, (float)Math.PI);
}
[Fact]
public void MathF_Ceililng_Is_Equal()
{
Assert.Equal(MathF.Ceiling(0.3333F), (float)Math.Ceiling(0.3333F));
}
[Fact]
public void MathF_Cos_Is_Equal()
{
Assert.Equal(MathF.Cos(0.3333F), (float)Math.Cos(0.3333F));
}
[Fact]
public void MathF_Abs_Is_Equal()
{
Assert.Equal(MathF.Abs(-0.3333F), (float)Math.Abs(-0.3333F));
}
[Fact]
public void MathF_Atan2_Is_Equal()
{
Assert.Equal(MathF.Atan2(1.2345F, 1.2345F), (float)Math.Atan2(1.2345F, 1.2345F));
}
[Fact]
public void MathF_Exp_Is_Equal()
{
Assert.Equal(MathF.Exp(1.2345F), (float)Math.Exp(1.2345F));
}
[Fact]
public void MathF_Floor_Is_Equal()
{
Assert.Equal(MathF.Floor(1.2345F), (float)Math.Floor(1.2345F));
}
[Fact]
public void MathF_Min_Is_Equal()
{
Assert.Equal(MathF.Min(1.2345F, 5.4321F), (float)Math.Min(1.2345F, 5.4321F));
}
[Fact]
public void MathF_Max_Is_Equal()
{
Assert.Equal(MathF.Max(1.2345F, 5.4321F), (float)Math.Max(1.2345F, 5.4321F));
}
[Fact]
public void MathF_Pow_Is_Equal()
{
Assert.Equal(MathF.Pow(1.2345F, 5.4321F), (float)Math.Pow(1.2345F, 5.4321F));
}
[Fact]
public void MathF_Round_Is_Equal()
{
Assert.Equal(MathF.Round(1.2345F), (float)Math.Round(1.2345F));
}
[Fact]
public void MathF_Round_With_Midpoint_Is_Equal()
{
Assert.Equal(MathF.Round(1.2345F, MidpointRounding.AwayFromZero), (float)Math.Round(1.2345F, MidpointRounding.AwayFromZero));
}
[Fact]
public void MathF_Sin_Is_Equal()
{
Assert.Equal(MathF.Sin(1.2345F), (float)Math.Sin(1.2345F));
}
[Fact]
public void MathF_SinC_Is_Equal()
{
float f = 1.2345F;
float expected = 1F;
if (Math.Abs(f) > Constants.Epsilon)
{
f *= (float)Math.PI;
float sinC = (float)Math.Sin(f) / f;
expected = Math.Abs(sinC) < Constants.Epsilon ? 0F : sinC;
}
Assert.Equal(MathF.SinC(1.2345F), expected);
}
[Fact]
public void MathF_Sqrt_Is_Equal()
{
Assert.Equal(MathF.Sqrt(2F), (float)Math.Sqrt(2F));
}
[Fact]
public void Convert_Degree_To_Radian()
{
Assert.Equal((float)(Math.PI / 2D), MathF.DegreeToRadian(90F), new FloatRoundingComparer(6));
}
[Fact]
public void Convert_Radian_To_Degree()
{
Assert.Equal(60F, MathF.RadianToDegree((float)(Math.PI / 3D)), new FloatRoundingComparer(5));
}
}
}

4
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
@ -245,7 +247,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
var options = new ResizeOptions
{
Size = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)),
Size = new Size((int)Math.Round(image.Width * .75F), (int)Math.Round(image.Height * .95F)),
Mode = ResizeMode.Min
};

Loading…
Cancel
Save