Skip to content

Commit 4407990

Browse files
committed
Better test for mode score calculation 4X4
1 parent 280e376 commit 4407990

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static void RunVp8Sse16X16Test()
140140
int expected = 2063;
141141

142142
// act
143-
int actual = LossyUtils.Vp8_Sse16X16(a, b);
143+
int actual = LossyUtils.Vp8_Sse16x16(a, b);
144144

145145
// assert
146146
Assert.Equal(expected, actual);
@@ -186,7 +186,7 @@ private static void RunVp8Sse16X8Test()
186186
int expected = 749;
187187

188188
// act
189-
int actual = LossyUtils.Vp8_Sse16X8(a, b);
189+
int actual = LossyUtils.Vp8_Sse16x8(a, b);
190190

191191
// assert
192192
Assert.Equal(expected, actual);
@@ -195,33 +195,25 @@ private static void RunVp8Sse16X8Test()
195195
private static void RunVp8Sse4X4Test()
196196
{
197197
// arrange
198-
byte[] a =
198+
Random rand = new(1234);
199+
byte[] a = new byte[128 * 10];
200+
byte[] b = new byte[128 * 10];
201+
for (int i = 0; i < a.Length; i++)
199202
{
200-
27, 27, 28, 29, 29, 28, 27, 27, 27, 28, 28, 29, 29, 28, 28, 27, 129, 129, 129, 129, 129, 129, 129,
201-
129, 128, 128, 128, 128, 128, 128, 128, 128, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 29, 29, 28,
202-
28, 27, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 27, 27, 26,
203-
26, 26, 26, 27, 27, 27, 28, 28, 29, 29, 28, 28, 27, 129, 129, 129, 129, 129, 129, 129, 129, 128,
204-
128, 128, 128, 128, 128, 128, 128, 28, 27, 27, 26, 26, 27, 27, 28, 27, 28, 28, 29, 29, 28, 28, 27,
205-
129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128
206-
};
207-
208-
byte[] b =
203+
a[i] = (byte)rand.Next(byte.MaxValue);
204+
b[i] = (byte)rand.Next(byte.MaxValue);
205+
}
206+
int[] expected = { 194133, 125861, 165966, 195688, 106491, 173015, 266960, 200272, 311224, 122545 };
207+
208+
// act + assert
209+
int offset = 0;
210+
for (int i = 0; i < expected.Length; i++)
209211
{
210-
26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 204, 204, 204, 204, 204, 204, 204,
211-
204, 204, 204, 204, 204, 204, 204, 204, 204, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
212-
28, 28, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 26, 26, 26,
213-
26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 204, 204, 204, 204, 204, 204, 204, 204, 204,
214-
204, 204, 204, 204, 204, 204, 204, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
215-
204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204
216-
};
212+
int actual = LossyUtils.Vp8_Sse4x4(a.AsSpan(offset), b.AsSpan(offset));
213+
Assert.Equal(expected[i], actual);
217214

218-
int expected = 27;
219-
220-
// act
221-
int actual = LossyUtils.Vp8_Sse4X4(a, b);
222-
223-
// assert
224-
Assert.Equal(expected, actual);
215+
offset += 128;
216+
}
225217
}
226218

227219
private static void RunMean16x4Test()
@@ -329,12 +321,15 @@ private static void RunHadamardTransformTest()
329321
[Fact]
330322
public void Vp8Sse16X8_WithoutAVX2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVp8Sse16X8Test, HwIntrinsics.DisableAVX2);
331323

324+
// This will test the AVX2 version.
332325
[Fact]
333326
public void Vp8Sse4X4_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVp8Sse4X4Test, HwIntrinsics.AllowAll);
334327

328+
// This will test the fallback scalar version.
335329
[Fact]
336-
public void Vp8Sse4X4_WithoutSSE2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVp8Sse4X4Test, HwIntrinsics.DisableSSE2);
330+
public void Vp8Sse4X4_WithoutHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVp8Sse4X4Test, HwIntrinsics.DisableSSE2 | HwIntrinsics.DisableAVX);
337331

332+
// This will test the SSE2 version.
338333
[Fact]
339334
public void Vp8Sse4X4_WithoutAVX2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVp8Sse4X4Test, HwIntrinsics.DisableAVX2);
340335

0 commit comments

Comments
 (0)