From 509f0a125c8f76c34cc3956d1232f788d93550de Mon Sep 17 00:00:00 2001 From: Grisha Kotler Date: Wed, 9 Oct 2024 16:54:25 +0300 Subject: [PATCH] RavenDB-22986 - adjust tests --- test/SlowTests/Voron/StreamBitArrayTests.cs | 94 ++++++++++++++++++--- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/test/SlowTests/Voron/StreamBitArrayTests.cs b/test/SlowTests/Voron/StreamBitArrayTests.cs index 15d7a2296d41..d99ba4b3d4de 100644 --- a/test/SlowTests/Voron/StreamBitArrayTests.cs +++ b/test/SlowTests/Voron/StreamBitArrayTests.cs @@ -1,9 +1,10 @@ -using FastTests; +using System; +using FastTests; +using SlowTests.Utils; using Xunit; using Xunit.Abstractions; using Voron.Impl.FreeSpace; using Tests.Infrastructure; -using Random = System.Random; namespace SlowTests.Voron { @@ -12,11 +13,79 @@ public class StreamBitArrayTests : NoDisposalNeeded public StreamBitArrayTests(ITestOutputHelper output) : base(output) { } - + + [RavenFact(RavenTestCategory.Voron)] + public void VerifySingleSmallResult() + { + int[] arr = + [ + 962919237, 1548146341, 887074999, -1149229772, 1614889381, 1195459377, 241536840, 1976691873, 974616527, -1975930694, -842246417, 1992663471, -441749934, + 1493649717, -1200378937, 316033463, 1754441570, -1514685861, 2086876795, -2023483551, -850791867, 2122928129, -2028633376, -1888571066, -1887046545, + -674291990, 937660561, 1660582309, -1011073175, -460586860, 145201398, 545934217, -1348896473, 529588057, -2125877939, 748147114, 304154730, -553437939, + -1685030522, 65856665, -2095037481, 1700335264, 1057375282, 488608589, -968824882, -942978190, -14718, 1690458861, -1432094240, -68039965, -392179582, + -1532304670, 695723974, -1515228467, -63736809, -271307999, 311526503, -1606718741, 2089777125, -633659368, -1900351717, 1564141405, 1909671261, 5492821 + ]; + + var sba = new StreamBitArray(); + var sba2 = new StreamBitArray2(); + + for (var wordIndex = 0; wordIndex < arr.Length; wordIndex++) + { + var word = arr[wordIndex]; + for (int i = 0; i < 32; i++) + { + if ((word & (1 << i)) == 0) + continue; + + int globalIndex = wordIndex * 32 + i; + sba.Set(globalIndex, true); + sba2.Set(globalIndex, true); + } + } + + const int num = 19; + var result1 = sba.GetContinuousRangeStart(num); + var result2 = GetContinuousRangeSlow(sba, num); + Assert.Equal(result1, result2); + } + [RavenFact(RavenTestCategory.Voron)] - public void VerifyResultWithRandomInput() + public void VerifySingleLargeResult() + { + int[] arr = + [ + 0, 0, 0, 0, 0, 0, -256, -1, -1, -1, -1, -1, 65535, 0, 0, 0, 0, 0, -16777216, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, -256, -1, -1, -1, -1, -1, 65535, 0, + 0, 0, 0, 0, -16777216, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, -256, -1, -1, -1, -1, -1, 65535, 0 + ]; + + var sba = new StreamBitArray(); + var sba2 = new StreamBitArray2(); + + for (var wordIndex = 0; wordIndex < arr.Length; wordIndex++) + { + var word = arr[wordIndex]; + for (int i = 0; i < 32; i++) + { + if ((word & (1 << i)) == 0) + continue; + + int globalIndex = wordIndex * 32 + i; + sba.Set(globalIndex, true); + sba2.Set(globalIndex, true); + } + } + + const int num = 100; + var result1 = sba.GetContinuousRangeStart(num); + var result2 = GetContinuousRangeSlow(sba, num); + Assert.Equal(result1, result2); + } + + [RavenTheory(RavenTestCategory.Voron)] + [InlineDataWithRandomSeed] + public void VerifyResultWithRandomInput(int seed) { - var random = new Random(); + var random = new Random(seed); var sba = new StreamBitArray(); for (int j = 0; j < 2048; j += 1) @@ -33,13 +102,14 @@ public void VerifyResultWithRandomInput() } [RavenTheory(RavenTestCategory.Voron)] - [InlineData(1, 2)] - [InlineData(2, 32)] - [InlineData(32, 300)] - [InlineData(500, 600)] - public void VerifyResultWithRandomMinMaxInput(int minContinuous, int maxContinuous) + [InlineDataWithRandomSeed(1, 2)] + [InlineDataWithRandomSeed(2, 32)] + [InlineDataWithRandomSeed(32, 300)] + [InlineDataWithRandomSeed(32, 2048)] + [InlineDataWithRandomSeed(1, 2048)] + public void VerifyResultWithRandomMinMaxInput(int minContinuous, int maxContinuous, int seed) { - var random = new Random(); + var random = new Random(seed); var sba = new StreamBitArray(); int i = 0; @@ -63,7 +133,7 @@ public void VerifyResultWithRandomMinMaxInput(int minContinuous, int maxContinuo } } - public static int? GetContinuousRangeSlow(StreamBitArray current, int num) + private static int? GetContinuousRangeSlow(StreamBitArray current, int num) { var start = -1; var count = 0;