From 533a7cabf307b7fbea9a91e47f616a0964bbf53d Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 6 Oct 2026 14:14:38 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=99=E3=82=AF=E3=83=88=E3=83=AB=E6=BC=94?= =?UTF-8?q?=E7=AE=97=E3=81=AE=E7=B4=A0=E6=9D=90=E3=81=AE=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E3=81=AE=E8=A9=A6=E9=A8=93=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WaveOptics.Tests/WaveOpticsSourceHashTests.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/WaveOptics.Tests/WaveOpticsSourceHashTests.cs b/WaveOptics.Tests/WaveOpticsSourceHashTests.cs index 7d8bbae..10a77a9 100644 --- a/WaveOptics.Tests/WaveOpticsSourceHashTests.cs +++ b/WaveOptics.Tests/WaveOpticsSourceHashTests.cs @@ -70,4 +70,51 @@ public sealed class WaveOpticsSourceHashTests { Assert.Throws(() => WaveOpticsSourceHash.Compute(new byte[15], 0, 0, 2, 2)); } + + [Theory] + [InlineData(1, 1, 0.0)] + [InlineData(1, 5, 1.0)] + [InlineData(7, 3, 0.5)] + [InlineData(8, 4, 0.01)] + [InlineData(9, 4, 0.3)] + [InlineData(15, 6, 1.0)] + [InlineData(16, 6, 0.0)] + [InlineData(17, 3, 0.02)] + [InlineData(63, 9, 0.6)] + [InlineData(64, 9, 1.0)] + [InlineData(1000, 7, 0.001)] + [InlineData(1000, 7, 0.9)] + public void TheVectorHashMatchesTheScalarOneBitForBit(int width, int height, double litFraction) + { + var pixels = RandomPixels(width, height, width * 31 + height, litFraction); + var bytes = MemoryMarshal.AsBytes(pixels.AsSpan()); + + var expected = WaveOpticsSourceHash.ComputeScalar(bytes, 12, 7, width, height); + var actual = WaveOpticsSourceHash.Compute(bytes, 12, 7, width, height); + + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(19)] + [InlineData(32)] + public void ASingleLitPixelIsFoundWhereverItSits(int width) + { + const int Height = 3; + for (var y = 0; y < Height; y++) + { + for (var x = 0; x < width; x++) + { + var pixels = new int[width * Height]; + pixels[y * width + x] = 0x01020304; + var bytes = MemoryMarshal.AsBytes(pixels.AsSpan()); + + var expected = WaveOpticsSourceHash.ComputeScalar(bytes, 5, 9, width, Height); + var actual = WaveOpticsSourceHash.Compute(bytes, 5, 9, width, Height); + + Assert.Equal(expected, actual); + Assert.Equal((1, 5 + x, 9 + y, 5 + x, 9 + y), (actual.LitCount, actual.MinimumX, actual.MinimumY, actual.MaximumX, actual.MaximumY)); + } + } + } }