public void Test_KeyRange_Contains() { KeyRange range; // ["", "") range = KeyRange.Empty; Assert.That(range.Contains(Slice.Empty), Is.False); Assert.That(range.Contains(Slice.FromByteString("\x00")), Is.False); Assert.That(range.Contains(Slice.FromByteString("hello")), Is.False); Assert.That(range.Contains(Slice.FromByteString("\xFF")), Is.False); // ["", "\xFF" ) range = KeyRange.Create(Slice.Empty, Slice.FromByteString("\xFF")); Assert.That(range.Contains(Slice.Empty), Is.True); Assert.That(range.Contains(Slice.FromByteString("\x00")), Is.True); Assert.That(range.Contains(Slice.FromByteString("hello")), Is.True); Assert.That(range.Contains(Slice.FromByteString("\xFF")), Is.False); // ["\x00", "\xFF" ) range = KeyRange.Create(Slice.FromByteString("\x00"), Slice.FromByteString("\xFF")); Assert.That(range.Contains(Slice.Empty), Is.False); Assert.That(range.Contains(Slice.FromByteString("\x00")), Is.True); Assert.That(range.Contains(Slice.FromByteString("hello")), Is.True); Assert.That(range.Contains(Slice.FromByteString("\xFF")), Is.False); // corner cases Assert.That(KeyRange.Create(Slice.FromByteString("A"), Slice.FromByteString("A")).Contains(Slice.FromByteString("A")), Is.False, "Equal bounds"); }
public void Test_KeyRange_Test() { const int BEFORE = -1, INSIDE = 0, AFTER = +1; KeyRange range; // range: [ "A", "Z" ) range = KeyRange.Create(Slice.FromByteString("A"), Slice.FromByteString("Z")); // Excluding the end: < "Z" Assert.That(range.Test(Slice.FromByteString("\x00"), endIncluded: false), Is.EqualTo(BEFORE)); Assert.That(range.Test(Slice.FromByteString("@"), endIncluded: false), Is.EqualTo(BEFORE)); Assert.That(range.Test(Slice.FromByteString("A"), endIncluded: false), Is.EqualTo(INSIDE)); Assert.That(range.Test(Slice.FromByteString("Z"), endIncluded: false), Is.EqualTo(AFTER)); Assert.That(range.Test(Slice.FromByteString("Z\x00"), endIncluded: false), Is.EqualTo(AFTER)); Assert.That(range.Test(Slice.FromByteString("\xFF"), endIncluded: false), Is.EqualTo(AFTER)); // Including the end: <= "Z" Assert.That(range.Test(Slice.FromByteString("\x00"), endIncluded: true), Is.EqualTo(BEFORE)); Assert.That(range.Test(Slice.FromByteString("@"), endIncluded: true), Is.EqualTo(BEFORE)); Assert.That(range.Test(Slice.FromByteString("A"), endIncluded: true), Is.EqualTo(INSIDE)); Assert.That(range.Test(Slice.FromByteString("Z"), endIncluded: true), Is.EqualTo(INSIDE)); Assert.That(range.Test(Slice.FromByteString("Z\x00"), endIncluded: true), Is.EqualTo(AFTER)); Assert.That(range.Test(Slice.FromByteString("\xFF"), endIncluded: true), Is.EqualTo(AFTER)); range = KeyRange.Create(TuPack.EncodeKey("A"), TuPack.EncodeKey("Z")); Assert.That(range.Test(TuPack.EncodeKey("@")), Is.EqualTo((BEFORE))); Assert.That(range.Test(TuPack.EncodeKey("A")), Is.EqualTo((INSIDE))); Assert.That(range.Test(TuPack.EncodeKey("Z")), Is.EqualTo((AFTER))); Assert.That(range.Test(TuPack.EncodeKey("Z"), endIncluded: true), Is.EqualTo(INSIDE)); }
public void Test_KeyRange_Disjoint() { KeyRange MakeRange(byte x, byte y) => KeyRange.Create(Slice.FromByte(x), Slice.FromByte(y)); #region Disjoint... // [0, 1) [2, 3) // #X // #X Assert.That(MakeRange(0, 1).Disjoint(MakeRange(2, 3)), Is.True); // [2, 3) [0, 1) // #X // #X Assert.That(MakeRange(2, 3).Disjoint(MakeRange(0, 1)), Is.True); #endregion #region Not Disjoint... // [0, 1) [1, 2) // #X // #X Assert.That(MakeRange(0, 1).Disjoint(MakeRange(1, 2)), Is.False); // [1, 2) [0, 1) // #X // #X Assert.That(MakeRange(1, 2).Disjoint(MakeRange(0, 1)), Is.False); // [0, 2) [1, 3) // ##X // ##X Assert.That(MakeRange(0, 2).Disjoint(MakeRange(1, 3)), Is.False); // [1, 3) [0, 2) // ##X // ##X Assert.That(MakeRange(1, 3).Disjoint(MakeRange(0, 2)), Is.False); // [0, 1) [0, 2) // #X // ##X Assert.That(MakeRange(0, 1).Disjoint(MakeRange(0, 2)), Is.False); // [0, 2) [0, 1) // ##X // #X Assert.That(MakeRange(0, 2).Disjoint(MakeRange(0, 1)), Is.False); // [0, 2) [1, 2) // ##X // #X Assert.That(MakeRange(0, 2).Disjoint(MakeRange(1, 2)), Is.False); // [1, 2) [0, 2) // #X // ##X Assert.That(MakeRange(1, 2).Disjoint(MakeRange(0, 2)), Is.False); #endregion }
public void Test_KeyRange_Intersects() { Func <byte, byte, KeyRange> range = (x, y) => KeyRange.Create(Slice.FromByte(x), Slice.FromByte(y)); #region Not Intersecting... // [0, 1) [2, 3) // #X // #X Assert.That(range(0, 1).Intersects(range(2, 3)), Is.False); // [2, 3) [0, 1) // #X // #X Assert.That(range(2, 3).Intersects(range(0, 1)), Is.False); // [0, 1) [1, 2) // #X // #X Assert.That(range(0, 1).Intersects(range(1, 2)), Is.False); // [1, 2) [0, 1) // #X // #X Assert.That(range(1, 2).Intersects(range(0, 1)), Is.False); #endregion #region Intersecting... // [0, 2) [1, 3) // ##X // ##X Assert.That(range(0, 2).Intersects(range(1, 3)), Is.True); // [1, 3) [0, 2) // ##X // ##X Assert.That(range(1, 3).Intersects(range(0, 2)), Is.True); // [0, 1) [0, 2) // #X // ##X Assert.That(range(0, 1).Intersects(range(0, 2)), Is.True); // [0, 2) [0, 1) // ##X // #X Assert.That(range(0, 2).Intersects(range(0, 1)), Is.True); // [0, 2) [1, 2) // ##X // #X Assert.That(range(0, 2).Intersects(range(1, 2)), Is.True); // [1, 2) [0, 2) // #X // ##X Assert.That(range(1, 2).Intersects(range(0, 2)), Is.True); #endregion }