Skip to content

Commit 3e1715e

Browse files
committed
relax comparison on .NET Framework
1 parent cdeafe3 commit 3e1715e

5 files changed

Lines changed: 19 additions & 30 deletions

File tree

tests/ImageSharp.Drawing.Tests/Drawing/DrawingRobustnessTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public void LargeGeoJson_Lines(TestImageProvider<Rgba32> provider, string geoJso
108108
public void LargeGeoJson_States_Fill(TestImageProvider<Rgba32> provider)
109109
{
110110
using Image<Rgba32> image = FillGeoJsonPolygons(provider, TestImages.GeoJson.States, 16, new Vector2(60), new Vector2(0, -1000));
111+
ImageComparer comparer = ImageComparer.TolerantPercentage(0.001f);
112+
111113
image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
112-
image.CompareToReferenceOutput(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
114+
image.CompareToReferenceOutput(comparer, provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
113115
}
114116

115117
private Image<Rgba32> FillGeoJsonPolygons(TestImageProvider<Rgba32> provider, string geoJsonFile, int aa, Vector2 scale, Vector2 pixelOffset)
@@ -159,12 +161,17 @@ public void LargeGeoJson_Mississippi_Lines(TestImageProvider<Rgba32> provider, i
159161
image.Mutate(c => c.DrawLines(Color.White, 1.0f, loop));
160162
}
161163

162-
// Very strict tolerance, since the image is sparse:
163-
ImageComparer comparer = ImageComparer.TolerantPercentage(1e-7f);
164+
// Very strict tolerance, since the image is sparse (relaxed on .NET Framework)
165+
ImageComparer comparer = TestEnvironment.IsFramework
166+
? ImageComparer.TolerantPercentage(1e-3f)
167+
: ImageComparer.TolerantPercentage(1e-7f);
168+
164169
string details = $"PixelOffset({pixelOffset})";
165170
image.DebugSave(provider, details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
166171
image.CompareToReferenceOutput(comparer, provider, testOutputDetails: details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
167172
}
173+
174+
168175

169176
[Theory(Skip = "For local experiments only")]
170177
[InlineData(0)]

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public class DrawTextOnImageTests
2525

2626
private const string TestText = "Sphinx of black quartz, judge my vow\n0123456789";
2727

28-
public static ImageComparer TextDrawingComparer = ImageComparer.TolerantPercentage(1e-5f);
28+
public static ImageComparer TextDrawingComparer = TestEnvironment.IsFramework
29+
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework
30+
: ImageComparer.TolerantPercentage(1e-5f);
31+
2932
public static ImageComparer OutlinedTextDrawingComparer = ImageComparer.TolerantPercentage(5e-4f);
30-
// public static ImageComparer TextDrawingComparer = ImageComparer.TolerantPercentage(0.1f);
31-
// public static ImageComparer OutlinedTextDrawingComparer = ImageComparer.TolerantPercentage(0.2f);
3233

3334
public DrawTextOnImageTests(ITestOutputHelper output)
3435
{
@@ -155,7 +156,7 @@ public void FontShapesAreRenderedCorrectly<TPixel>(
155156
{
156157
Font font = CreateFont(fontName, fontSize);
157158
var color = Color.Black;
158-
159+
159160
provider.RunValidatingProcessorTest(
160161
c =>
161162
{

tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ public void NegativeOrientation01(IntersectionRule intersectionRule)
451451
{
452452
Empty(4f),
453453

454-
(4.25f, new FuzzyFloat[] {13, 13}),
454+
// Eps = 0.01 to address inaccuracies on .NET Framework
455+
(4.25f, new FuzzyFloat[] { F(13, 0.01f), F(13, 0.01f)}),
455456
(4.5f, new FuzzyFloat[] {F(12.714286f, 0.5f), F(13.444444f, 0.5f), 16, 16}),
456457
(4.75f, new FuzzyFloat[] {F(12.357143f, 0.5f), 14, 14, 16}),
457458
(5f, new FuzzyFloat[] {12, 16}),
@@ -529,7 +530,6 @@ public void NumericCornerCases_Offset(float offset, string name, (float y, Fuzzy
529530
TestScan(poly, min, max, 4, expectedIntersections.Select(i => i.x).ToArray());
530531
}
531532

532-
533533
private static (float y, FuzzyFloat[] x)[] TranslateIntersections(
534534
(float y, FuzzyFloat[] x)[] ex, float dx, float dy)
535535
{

tests/ImageSharp.Drawing.Tests/TestUtilities/FuzzyFloat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.TestUtilities
1111
/// </summary>
1212
public struct FuzzyFloat : IEquatable<float>, IXunitSerializable
1313
{
14-
public const float DefaultEpsilon = 1e-5f;
14+
public static readonly float DefaultEpsilon = 1e-5f;
1515

1616
private float value;
1717
private float min;

tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ public static partial class TestEnvironment
3131
return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi;
3232
});
3333

34-
private static readonly Lazy<string> NetCoreVersionLazy = new Lazy<string>(GetNetCoreVersion);
35-
36-
/// <summary>
37-
/// Gets the .NET Core version, if running on .NET Core, otherwise returns an empty string.
38-
/// </summary>
39-
internal static string NetCoreVersion => NetCoreVersionLazy.Value;
34+
internal static bool IsFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");
4035

4136
// ReSharper disable once InconsistentNaming
4237
/// <summary>
@@ -132,19 +127,5 @@ internal static string CreateOutputDirectory(string path, params string[] pathPa
132127

133128
return path;
134129
}
135-
136-
/// <summary>
137-
/// Solution borrowed from:
138-
/// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100
139-
/// </summary>
140-
private static string GetNetCoreVersion()
141-
{
142-
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
143-
string[] assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
144-
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
145-
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
146-
return assemblyPath[netCoreAppIndex + 1];
147-
return "";
148-
}
149130
}
150131
}

0 commit comments

Comments
 (0)