Skip to content

Commit 5dde961

Browse files
committed
add more tests
1 parent 7de212a commit 5dde961

File tree

1 file changed

+70
-32
lines changed

1 file changed

+70
-32
lines changed

test/Garnet.test/GarnetBitmapTests.cs

+70-32
Original file line numberDiff line numberDiff line change
@@ -2316,38 +2316,6 @@ public void BitmapBitPosFixedTests()
23162316
ClassicAssert.AreEqual(8, pos);
23172317
}
23182318

2319-
[Test, Order(34)]
2320-
[Category("BITPOS")]
2321-
public void BitmapBitPosBitOffsetTests([Values] bool searchFor)
2322-
{
2323-
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
2324-
var db = redis.GetDatabase(0);
2325-
2326-
var key = "mykey";
2327-
byte[] value = searchFor ?
2328-
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] :
2329-
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
2330-
_ = db.StringSet(key, value);
2331-
2332-
var bitLength = value.Length * 8;
2333-
var expectedPosOffset = 5;
2334-
2335-
for (var i = 0; i < 10; i++)
2336-
{
2337-
// Set or clear bit
2338-
_ = db.StringSetBit(key, offset: expectedPosOffset, bit: searchFor);
2339-
2340-
// Find pos of bit set/clear
2341-
var pos = db.StringBitPosition(key, bit: searchFor, 0, 19, StringIndexType.Bit);
2342-
ClassicAssert.AreEqual(expectedPosOffset, pos);
2343-
2344-
// Toggle bit back to initial value
2345-
_ = db.StringSetBit(key, offset: expectedPosOffset, bit: !searchFor);
2346-
2347-
expectedPosOffset++;
2348-
}
2349-
}
2350-
23512319
[Test, Order(35)]
23522320
[Category("BITOP")]
23532321
public void BitmapOperationNonExistentSourceKeys()
@@ -2402,5 +2370,75 @@ public void BitmapOperationTooManyKeys()
24022370
ClassicAssert.AreEqual("ERR Bitop source key limit (64) exceeded", ex.Message);
24032371
}
24042372
}
2373+
2374+
[Test, Order(38)]
2375+
[Category("BITPOS")]
2376+
public void BitmapBitPosBitOffsetTests([Values] bool searchFor)
2377+
{
2378+
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
2379+
var db = redis.GetDatabase(0);
2380+
2381+
var key = "mykey";
2382+
byte[] value = searchFor ?
2383+
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] :
2384+
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
2385+
_ = db.StringSet(key, value);
2386+
2387+
var bitLength = value.Length * 8;
2388+
var expectedPosOffset = 5;
2389+
2390+
for (var i = 0; i < 10; i++)
2391+
{
2392+
// Set or clear bit
2393+
_ = db.StringSetBit(key, offset: expectedPosOffset, bit: searchFor);
2394+
2395+
// Find pos of bit set/clear
2396+
var pos = db.StringBitPosition(key, bit: searchFor, 0, 19, StringIndexType.Bit);
2397+
ClassicAssert.AreEqual(expectedPosOffset, pos);
2398+
2399+
// Toggle bit back to initial value
2400+
_ = db.StringSetBit(key, offset: expectedPosOffset, bit: !searchFor);
2401+
2402+
expectedPosOffset++;
2403+
}
2404+
}
2405+
2406+
[Test, Order(38)]
2407+
[Category("BITPOS")]
2408+
public void BitmapBitPosBitInvalidMaskTests()
2409+
{
2410+
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
2411+
var db = redis.GetDatabase(0);
2412+
2413+
var key = "mykey";
2414+
// 0x3e = 00111110
2415+
byte[] value = [0x3e];
2416+
_ = db.StringSet(key, value);
2417+
2418+
// 0x3e = 00111110
2419+
var pos = db.StringBitPosition(key, bit: false, start: 0, end: 5, StringIndexType.Bit);
2420+
ClassicAssert.AreEqual(0, pos);
2421+
2422+
pos = db.StringBitPosition(key, bit: false, start: 1, end: 5, StringIndexType.Bit);
2423+
ClassicAssert.AreEqual(1, pos);
2424+
2425+
pos = db.StringBitPosition(key, bit: false, start: 2, end: 5, StringIndexType.Bit);
2426+
ClassicAssert.AreEqual(-1, pos);
2427+
2428+
pos = db.StringBitPosition(key, bit: false, start: 2, end: 6, StringIndexType.Bit);
2429+
ClassicAssert.AreEqual(-1, pos);
2430+
2431+
pos = db.StringBitPosition(key, bit: false, start: 2, end: 7, StringIndexType.Bit);
2432+
ClassicAssert.AreEqual(7, pos);
2433+
2434+
// 0x7e02 = 0111111000000010
2435+
value = [0x7e, 0x02];
2436+
_ = db.StringSet(key, value);
2437+
pos = db.StringBitPosition(key, bit: true, start: 7, end: 13, StringIndexType.Bit);
2438+
ClassicAssert.AreEqual(-1, pos);
2439+
2440+
pos = db.StringBitPosition(key, bit: true, start: 7, end: 14, StringIndexType.Bit);
2441+
ClassicAssert.AreEqual(14, pos);
2442+
}
24052443
}
24062444
}

0 commit comments

Comments
 (0)