-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
955 additions
and
869 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using FluentAssertions; | ||
using Paprika.Data; | ||
using static Paprika.Data.NibbleSelector; | ||
|
||
namespace Paprika.Tests.Data; | ||
|
||
[Parallelizable(ParallelScope.None)] | ||
public class NibbleSelectorTests | ||
{ | ||
private static readonly Type[] Selectors = typeof(NibbleSelector).GetNestedTypes(); | ||
private readonly HashSet<Type> _asserted = new(); | ||
|
||
[SetUp] | ||
public void Setup() => _asserted.Clear(); | ||
|
||
[TestCase((byte)0)] | ||
[TestCase((byte)1)] | ||
[TestCase((byte)2)] | ||
[TestCase((byte)3)] | ||
public void Range_Q0(byte nibble) | ||
{ | ||
True<All>(nibble); | ||
True<HalfLow>(nibble); | ||
True<Q0>(nibble); | ||
|
||
RestIsFalse(nibble); | ||
} | ||
|
||
[TestCase((byte)4)] | ||
[TestCase((byte)5)] | ||
[TestCase((byte)6)] | ||
[TestCase((byte)7)] | ||
public void Range_Q1(byte nibble) | ||
{ | ||
True<All>(nibble); | ||
True<HalfLow>(nibble); | ||
True<Q1>(nibble); | ||
|
||
RestIsFalse(nibble); | ||
} | ||
|
||
[TestCase((byte)8)] | ||
[TestCase((byte)9)] | ||
[TestCase((byte)10)] | ||
[TestCase((byte)11)] | ||
public void Range_Q2(byte nibble) | ||
{ | ||
True<All>(nibble); | ||
True<HalfHigh>(nibble); | ||
True<Q2>(nibble); | ||
|
||
RestIsFalse(nibble); | ||
} | ||
|
||
[TestCase((byte)12)] | ||
[TestCase((byte)13)] | ||
[TestCase((byte)14)] | ||
[TestCase((byte)15)] | ||
public void Range_Q3(byte nibble) | ||
{ | ||
True<All>(nibble); | ||
True<HalfHigh>(nibble); | ||
True<Q3>(nibble); | ||
|
||
RestIsFalse(nibble); | ||
} | ||
|
||
[Test(Description = "Should throw on non asserted one")] | ||
public void SanityCheck() | ||
{ | ||
var ex = Assert.Throws<Exception>(() => RestIsFalse(1)); | ||
|
||
ex.Message.Should().ContainAll(nameof(All), nameof(HalfLow), nameof(Q0)); | ||
} | ||
|
||
private void RestIsFalse(byte nibble) | ||
{ | ||
List<Type> failed = new(); | ||
|
||
foreach (var selector in Selectors) | ||
{ | ||
if (_asserted.Contains(selector)) | ||
continue; | ||
|
||
var result = (bool)((selector.GetMethod(nameof(INibbleSelector.Should)).Invoke(null, [nibble]))); | ||
if (result) | ||
{ | ||
failed.Add(selector); | ||
} | ||
} | ||
|
||
_asserted.Clear(); | ||
|
||
if (failed.Count > 0) | ||
{ | ||
throw new Exception( | ||
"The following selectors returned true while not asserted: " + string.Join(", ", failed)); | ||
} | ||
} | ||
|
||
private void True<TSelector>(byte nibble) where TSelector : INibbleSelector | ||
{ | ||
TSelector.Should(nibble).Should().BeTrue(); | ||
_asserted.Add(typeof(TSelector)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using FluentAssertions; | ||
using Paprika.Data; | ||
using Paprika.Store; | ||
|
||
namespace Paprika.Tests.Store; | ||
|
||
public class BottomPageTests : BasePageTests | ||
{ | ||
private const uint BatchId = 1; | ||
|
||
[Test] | ||
public void Sufficient_to_set() | ||
{ | ||
var batch = NewBatch(BatchId); | ||
var bottom = ((IBatchContext)batch).GetNewPage<BottomPage>(out _); | ||
|
||
var key = NibblePath.Empty; | ||
|
||
// construct keys so that they fall into child, grand-child left, grand-child rigth | ||
// Left child | ||
var key0 = NibblePath.FromKey([0x0A]); // 0 is 0th nibble | ||
var key1 = NibblePath.FromKey([0x4A]); // 4 is 0th nibble | ||
var key2 = NibblePath.FromKey([0x1A]); // 1 is 0th nibble | ||
|
||
// Right child | ||
var key8 = NibblePath.FromKey([0x8A]); // 8 is 0th nibble | ||
var key9 = NibblePath.FromKey([0xFA]); // 9 is 0th nibble | ||
var key10 = NibblePath.FromKey([0x9A]); // A is 0th nibble | ||
|
||
var v0 = new byte[3002]; | ||
var v1 = new byte[2999]; | ||
var v2 = new byte[2998]; | ||
var v8 = new byte[3003]; | ||
var v9 = new byte[3006]; | ||
var v10 = new byte[2980]; | ||
var v = new byte[3001]; | ||
|
||
bottom.Set(key0, v0, batch); | ||
bottom.Set(key1, v1, batch); | ||
bottom.Set(key2, v2, batch); | ||
bottom.Set(key8, v8, batch); | ||
bottom.Set(key9, v9, batch); | ||
bottom.Set(key10, v10, batch); | ||
bottom.Set(key, v, batch); | ||
|
||
Assert(key, v); | ||
Assert(key0, v0); | ||
Assert(key1, v1); | ||
Assert(key2, v2); | ||
Assert(key8, v8); | ||
Assert(key9, v9); | ||
Assert(key10, v10); | ||
return; | ||
|
||
void Assert(in NibblePath key, in ReadOnlySpan<byte> expected) | ||
{ | ||
bottom.TryGet(batch, key, out var actual).Should().BeTrue(); | ||
actual.SequenceEqual(expected).Should().BeTrue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.