From e2eb88e84483db6b37f97f501624de92d9f3cac9 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 11 Oct 2026 22:14:31 +0900 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E3=81=AE=E5=85=A5=E5=8A=9B=E3=81=A8?= =?UTF-8?q?=E8=A6=81=E6=B1=82=E3=81=99=E3=82=8B=E7=9F=A9=E5=BD=A2=E3=81=AE?= =?UTF-8?q?=E8=A9=A6=E9=A8=93=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SpectrumColorShiftEffectImplTests.cs | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 SpectrumColorShift.Tests/SpectrumColorShiftEffectImplTests.cs diff --git a/SpectrumColorShift.Tests/SpectrumColorShiftEffectImplTests.cs b/SpectrumColorShift.Tests/SpectrumColorShiftEffectImplTests.cs new file mode 100644 index 0000000..28b302c --- /dev/null +++ b/SpectrumColorShift.Tests/SpectrumColorShiftEffectImplTests.cs @@ -0,0 +1,118 @@ +using Vortice; +using static SpectrumColorShift.SpectrumColorShiftCustomEffect; + +namespace SpectrumColorShift.Tests; + +public sealed class SpectrumColorShiftEffectImplTests +{ + static RawRect Map(EffectImpl impl, RawRect input) + { + impl.MapInputRectsToOutputRect([input], [input], out var output, out _); + + return output; + } + + static RawRect Request(EffectImpl impl, RawRect tile) + { + var inputs = new RawRect[1]; + impl.MapOutputRectToInputRects(tile, inputs); + + return inputs[0]; + } + + [Theory] + [InlineData(10, 5, 10, 20)] + [InlineData(10, 5, 30, 5)] + [InlineData(10, 5, 10, 5)] + [InlineData(30, 5, 10, 20)] + [InlineData(10, 20, 30, 5)] + public void AnEmptyInputIsPassedThroughAsItIs(int left, int top, int right, int bottom) + { + var impl = new EffectImpl { Distance = 5f }; + + var output = Map(impl, new RawRect(left, top, right, bottom)); + + Assert.Equal(new RawRect(left, top, right, bottom), output); + } + + [Theory] + [InlineData(10, 5, 10, 20)] + [InlineData(10, 5, 30, 5)] + public void AnEmptyInputIsRequestedBackWhateverTheTile(int left, int top, int right, int bottom) + { + var impl = new EffectImpl { Distance = 5f }; + Map(impl, new RawRect(left, top, right, bottom)); + + var requested = Request(impl, new RawRect(0, 0, 50, 50)); + + Assert.Equal(new RawRect(left, top, right, bottom), requested); + } + + [Fact] + public void BeforeAnyInputNothingIsRequested() + { + var impl = new EffectImpl { Distance = 5f }; + + var requested = Request(impl, new RawRect(0, 0, 50, 50)); + + Assert.Equal(default, requested); + } + + [Fact] + public void ATileIsRequestedWithTheMarginOfTheShift() + { + var impl = new EffectImpl { Distance = 5f }; + Map(impl, new RawRect(0, 0, 40, 24)); + + var requested = Request(impl, new RawRect(0, 0, 50, 50)); + + Assert.Equal(new RawRect(-7, -2, 57, 52), requested); + } + + [Fact] + public void ANoInputRequestIsIgnored() + { + var impl = new EffectImpl { Distance = 5f }; + Map(impl, new RawRect(0, 0, 40, 24)); + + impl.MapOutputRectToInputRects(new RawRect(0, 0, 50, 50), []); + } + + [Fact] + public void AnInvalidInputInvalidatesTheShiftedOutput() + { + var impl = new EffectImpl { Distance = 10f }; + Map(impl, new RawRect(0, 0, 40, 24)); + + var invalid = impl.MapInvalidRect(0, new RawRect(0, 0, 40, 24)); + + Assert.Equal(new RawRect(-12, -2, 52, 26), invalid); + } + + [Fact] + public void EveryPropertyCanBeSetBeforeTheEffectIsDrawn() + { + var impl = new EffectImpl + { + Distance = 12f, + Mode = (int)ShiftMode.Rotational, + Angle = 45f, + CenterX = 7f, + CenterY = -3f, + Strength = 0.5f, + Dispersion = (int)DispersionLaw.Prism, + ReferenceWavelength = 480f, + Steps = 16, + }; + + Assert.Equal(12f, impl.Distance); + Assert.Equal((int)ShiftMode.Rotational, impl.Mode); + Assert.Equal(45f, impl.Angle, 0.01); + Assert.Equal(7f, impl.CenterX); + Assert.Equal(-3f, impl.CenterY); + Assert.Equal(0.5f, impl.Strength); + Assert.Equal((int)DispersionLaw.Prism, impl.Dispersion); + Assert.Equal(480f, impl.ReferenceWavelength); + Assert.Equal(16, impl.Steps); + } +}