From 045612f133daed0da16d244ab341a4b882d97ee0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 17 Feb 2021 11:33:37 +0000 Subject: [PATCH] Add tolerance to 32 bit tests --- .gitattributes | 33 ++++++++++++++----- .../Binarization/BinaryThresholdTest.cs | 27 ++++++++++++--- .../TestUtilities/TestEnvironment.cs | 13 ++------ 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/.gitattributes b/.gitattributes index 0f4f32655..6f0a3048c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,8 +2,13 @@ # Set default behavior to: # treat as text and # normalize to Unix-style line endings +############################################################################### * text eol=lf +############################################################################### # Set explicit file behavior to: +# treat as text and +# normalize to Unix-style line endings +############################################################################### *.asm text eol=lf *.c text eol=lf *.clj text eol=lf @@ -48,19 +53,35 @@ *.txt text eol=lf *.vb text eol=lf *.yml text eol=lf +############################################################################### +# Set explicit file behavior to: # treat as text # normalize to Unix-style line endings and # diff as csharp +############################################################################### *.cs text eol=lf diff=csharp +############################################################################### +# Set explicit file behavior to: +# treat as text +# normalize to Unix-style line endings and # use a union merge when resoling conflicts +############################################################################### *.csproj text eol=lf merge=union *.dbproj text eol=lf merge=union *.fsproj text eol=lf merge=union *.ncrunchproject text eol=lf merge=union *.vbproj text eol=lf merge=union +############################################################################### +# Set explicit file behavior to: +# treat as text # normalize to Windows-style line endings and +# use a union merge when resoling conflicts +############################################################################### *.sln text eol=crlf merge=union +############################################################################### +# Set explicit file behavior to: # treat as binary +############################################################################### *.basis binary *.bmp binary *.dds binary @@ -89,7 +110,10 @@ *.woff2 binary *.xls binary *.xlsx binary +############################################################################### +# Set explicit file behavior to: # diff as plain text +############################################################################### *.doc diff=astextplain *.docx diff=astextplain *.dot diff=astextplain @@ -98,12 +122,3 @@ *.rtf diff=astextplain *.svg diff=astextplain *.jpg,*.jpeg,*.bmp,*.gif,*.png,*.tif,*.tiff,*.tga,*.webp filter=lfs diff=lfs merge=lfs -text -*.jpg filter=lfs diff=lfs merge=lfs -text -*.jpeg filter=lfs diff=lfs merge=lfs -text -*.bmp filter=lfs diff=lfs merge=lfs -text -*.gif filter=lfs diff=lfs merge=lfs -text -*.png filter=lfs diff=lfs merge=lfs -text -*.tif filter=lfs diff=lfs merge=lfs -text -*.tiff filter=lfs diff=lfs merge=lfs -text -*.tga filter=lfs diff=lfs merge=lfs -text -*.webp filter=lfs diff=lfs merge=lfs -text diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 2a0696356..79ed4c7cd 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System.Globalization; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Binarization; @@ -64,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.Saturation)); image.DebugSave(provider, value); - image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo)); + image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); } } @@ -80,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.Saturation, bounds)); image.DebugSave(provider, value); - image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo)); + image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); } } @@ -93,7 +94,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.MaxChroma)); image.DebugSave(provider, value); - image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo)); + + if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework) + { + var comparer = ImageComparer.TolerantPercentage(0.0004F); + image.CompareToReferenceOutput(comparer, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); + } + else + { + image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); + } } } @@ -109,7 +119,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.MaxChroma, bounds)); image.DebugSave(provider, value); - image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo)); + + if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework) + { + var comparer = ImageComparer.TolerantPercentage(0.0004F); + image.CompareToReferenceOutput(comparer, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); + } + else + { + image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); + } } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 8d1b0f793..cb8a0df42 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -7,7 +7,6 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Tests { @@ -25,19 +24,11 @@ namespace SixLabors.ImageSharp.Tests private static readonly Lazy SolutionDirectoryFullPathLazy = new Lazy(GetSolutionDirectoryFullPathImpl); - private static readonly Lazy RunsOnCiLazy = new Lazy( - () => - { - bool isCi; - return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; - }); + private static readonly Lazy RunsOnCiLazy = new Lazy(() => bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi); private static readonly Lazy NetCoreVersionLazy = new Lazy(GetNetCoreVersion); - static TestEnvironment() - { - PrepareRemoteExecutor(); - } + static TestEnvironment() => PrepareRemoteExecutor(); /// /// Gets the .NET Core version, if running on .NET Core, otherwise returns an empty string.