Skip to content

Commit

Permalink
RavenDB-22986 - adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Oct 9, 2024
1 parent 4e66b6e commit 509f0a1
Showing 1 changed file with 82 additions and 12 deletions.
94 changes: 82 additions & 12 deletions test/SlowTests/Voron/StreamBitArrayTests.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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();

Check failure on line 30 in test/SlowTests/Voron/StreamBitArrayTests.cs

View workflow job for this annotation

GitHub Actions / Compile Server & Studio

The type or namespace name 'StreamBitArray2' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 30 in test/SlowTests/Voron/StreamBitArrayTests.cs

View workflow job for this annotation

GitHub Actions / Compile Server & Studio

The type or namespace name 'StreamBitArray2' could not be found (are you missing a using directive or an assembly reference?)

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();

Check failure on line 62 in test/SlowTests/Voron/StreamBitArrayTests.cs

View workflow job for this annotation

GitHub Actions / Compile Server & Studio

The type or namespace name 'StreamBitArray2' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 62 in test/SlowTests/Voron/StreamBitArrayTests.cs

View workflow job for this annotation

GitHub Actions / Compile Server & Studio

The type or namespace name 'StreamBitArray2' could not be found (are you missing a using directive or an assembly reference?)

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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 509f0a1

Please sign in to comment.