Skip to content

Commit

Permalink
Add testcases.
Browse files Browse the repository at this point in the history
  • Loading branch information
prvyk committed Feb 7, 2025
1 parent 5a67b08 commit 2957add
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/Garnet.test/RespSortedSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ public void AddWithOptions()
var added = db.SortedSetAdd(key, entries);
ClassicAssert.AreEqual(entries.Length, added);

var lex = db.SortedSetRangeByValue(key, default, "c");
CollectionAssert.AreEqual(new RedisValue[] { "a", "b", "c" }, lex);

// XX - Only update elements that already exist. Don't add new elements.
var testEntries = new[]
{
Expand All @@ -200,6 +203,8 @@ public void AddWithOptions()

added = db.SortedSetAdd(key, testEntries, SortedSetWhen.Exists);
ClassicAssert.AreEqual(0, added);
lex = db.SortedSetRangeByValue(key, default, "c");
CollectionAssert.AreEqual(new RedisValue[] { "a", "c", "b" }, lex);
var scores = db.SortedSetScores(key, [new RedisValue("a"), new RedisValue("b")]);
CollectionAssert.AreEqual(new double[] { 3, 4 }, scores);
var count = db.SortedSetLength(key);
Expand All @@ -216,6 +221,8 @@ public void AddWithOptions()

added = db.SortedSetAdd(key, testEntries, SortedSetWhen.NotExists);
ClassicAssert.AreEqual(2, added);
lex = db.SortedSetRangeByValue(key, default, "c");
CollectionAssert.AreEqual(new RedisValue[] { "a", "c", "b" }, lex);
scores = db.SortedSetScores(key, [new RedisValue("a"), new RedisValue("b"), new RedisValue("k"), new RedisValue("l")]);
CollectionAssert.AreEqual(new double[] { 3, 4, 11, 12 }, scores);
count = db.SortedSetLength(key);
Expand All @@ -231,6 +238,8 @@ public void AddWithOptions()

added = db.SortedSetAdd(key, testEntries, SortedSetWhen.LessThan);
ClassicAssert.AreEqual(1, added);
lex = db.SortedSetRangeByValue(key, default, "c");
CollectionAssert.AreEqual(new RedisValue[] { "a", "b", "c" }, lex);
scores = db.SortedSetScores(key, [new RedisValue("a"), new RedisValue("b"), new RedisValue("m")]);
CollectionAssert.AreEqual(new double[] { 3, 3, 13 }, scores);
count = db.SortedSetLength(key);
Expand All @@ -246,6 +255,8 @@ public void AddWithOptions()

added = db.SortedSetAdd(key, testEntries, SortedSetWhen.GreaterThan);
ClassicAssert.AreEqual(1, added);
lex = db.SortedSetRangeByValue(key, default, "c");
CollectionAssert.AreEqual(new RedisValue[] { "b", "c", "a" }, lex);
scores = db.SortedSetScores(key, [new RedisValue("a"), new RedisValue("b"), new RedisValue("n")]);
CollectionAssert.AreEqual(new double[] { 4, 3, 14 }, scores);
count = db.SortedSetLength(key);
Expand Down Expand Up @@ -2044,6 +2055,12 @@ public void CanDoZRangeByLex()
expectedResponse = "*3\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
ClassicAssert.AreEqual(expectedResponse, actualValue);

// ZRANGEBYLEX Synonym
response = lightClientRequest.SendCommand("ZRANGEBYLEX board - [c", 4);
//expectedResponse = "*3\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
ClassicAssert.AreEqual(expectedResponse, actualValue);
}

[Test]
Expand Down Expand Up @@ -2082,6 +2099,12 @@ public void CanDoZRangeByLexReverse()
expectedResponse = "*3\r\n$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
ClassicAssert.AreEqual(expectedResponse, actualValue);

// ZREVRANGEBYLEX Synonym
response = lightClientRequest.SendCommand("ZREVRANGEBYLEX board [c - REV", 4);
//expectedResponse = "*3\r\n$1\r\nc\r\n$1\r\nb\r\n$1\r\na\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
ClassicAssert.AreEqual(expectedResponse, actualValue);
}

[Test]
Expand All @@ -2098,6 +2121,12 @@ public void CanDoZRangeByLexWithLimit()
expectedResponse = "*3\r\n$7\r\nNewYork\r\n$5\r\nParis\r\n$5\r\nSeoul\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
ClassicAssert.AreEqual(expectedResponse, actualValue);

// ZRANGEBYLEX Synonym
response = lightClientRequest.SendCommand("ZRANGEBYLEX mycity - + LIMIT 2 3", 4);
//expectedResponse = "*3\r\n$7\r\nNewYork\r\n$5\r\nParis\r\n$5\r\nSeoul\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
ClassicAssert.AreEqual(expectedResponse, actualValue);
}


Expand Down

0 comments on commit 2957add

Please sign in to comment.