This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 874
/
Copy pathLexTests.cs
111 lines (91 loc) · 4.5 KB
/
LexTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using NUnit.Framework;
namespace ServiceStack.Redis.Tests
{
[TestFixture]
public class LexTests
: RedisClientTestsBase
{
readonly string[] values = "a,b,c,d,e,f,g".Split(',');
[SetUp]
public void SetUp()
{
Redis.FlushAll();
values.Each(x => Redis.ZAdd("zset", 0, x.ToUtf8Bytes()));
}
[Test]
public void Can_ZRangeByLex_all_entries()
{
var results = Redis.ZRangeByLex("zset", "-", "+");
Assert.That(results.Map(x => x.FromUtf8Bytes()), Is.EquivalentTo(values));
results = Redis.ZRangeByLex("zset", "-", "+", 1, 3);
Assert.That(results.Map(x => x.FromUtf8Bytes()), Is.EquivalentTo(new[] { "b", "c", "d" }));
}
[Test]
public void Can_ZRangeByLex_Desc()
{
var descInclusive = Redis.ZRangeByLex("zset", "-", "[c");
Assert.That(descInclusive.Map(x => x.FromUtf8Bytes()), Is.EquivalentTo(new[] { "a", "b", "c" }));
var descExclusive = Redis.ZRangeByLex("zset", "-", "(c");
Assert.That(descExclusive.Map(x => x.FromUtf8Bytes()), Is.EquivalentTo(new[] { "a", "b" }));
}
[Test]
public void Can_ZRangeByLex_Min_and_Max()
{
var range = Redis.ZRangeByLex("zset", "[aaa", "(g");
Assert.That(range.Map(x => x.FromUtf8Bytes()),
Is.EquivalentTo(new[] { "b", "c", "d", "e", "f" }));
}
[Test]
public void Can_ZlexCount()
{
var total = Redis.ZLexCount("zset", "-", "+");
Assert.That(total, Is.EqualTo(values.Length));
Assert.That(Redis.ZLexCount("zset", "-", "[c"), Is.EqualTo(3));
Assert.That(Redis.ZLexCount("zset", "-", "(c"), Is.EqualTo(2));
}
[Test]
public void Can_ZRemRangeByLex()
{
var removed = Redis.ZRemRangeByLex("zset", "[aaa", "(g");
Assert.That(removed, Is.EqualTo(5));
var remainder = Redis.ZRangeByLex("zset", "-", "+");
Assert.That(remainder.Map(x => x.FromUtf8Bytes()), Is.EqualTo(new[] { "a", "g" }));
}
[Test]
public void Can_SearchSortedSet()
{
Assert.That(Redis.SearchSortedSet("zset"), Is.EquivalentTo(values));
Assert.That(Redis.SearchSortedSet("zset", start: "-"), Is.EquivalentTo(values));
Assert.That(Redis.SearchSortedSet("zset", end: "+"), Is.EquivalentTo(values));
Assert.That(Redis.SearchSortedSet("zset", start: "[aaa").Count, Is.EqualTo(values.Length - 1));
Assert.That(Redis.SearchSortedSet("zset", end: "(g").Count, Is.EqualTo(values.Length - 1));
Assert.That(Redis.SearchSortedSet("zset", "[aaa", "(g").Count, Is.EqualTo(values.Length - 2));
Assert.That(Redis.SearchSortedSet("zset", "a", "c").Count, Is.EqualTo(3));
Assert.That(Redis.SearchSortedSet("zset", "[a", "[c").Count, Is.EqualTo(3));
Assert.That(Redis.SearchSortedSet("zset", "a", "(c").Count, Is.EqualTo(2));
Assert.That(Redis.SearchSortedSet("zset", "(a", "(c").Count, Is.EqualTo(1));
}
[Test]
public void Can_SearchSortedSetCount()
{
Assert.That(Redis.SearchSortedSet("zset"), Is.EquivalentTo(values));
Assert.That(Redis.SearchSortedSetCount("zset", start: "-"), Is.EqualTo(values.Length));
Assert.That(Redis.SearchSortedSetCount("zset", end: "+"), Is.EqualTo(values.Length));
Assert.That(Redis.SearchSortedSetCount("zset", start: "[aaa"), Is.EqualTo(values.Length - 1));
Assert.That(Redis.SearchSortedSetCount("zset", end: "(g"), Is.EqualTo(values.Length - 1));
Assert.That(Redis.SearchSortedSetCount("zset", "[aaa", "(g"), Is.EqualTo(values.Length - 2));
Assert.That(Redis.SearchSortedSetCount("zset", "a", "c"), Is.EqualTo(3));
Assert.That(Redis.SearchSortedSetCount("zset", "[a", "[c"), Is.EqualTo(3));
Assert.That(Redis.SearchSortedSetCount("zset", "a", "(c"), Is.EqualTo(2));
Assert.That(Redis.SearchSortedSetCount("zset", "(a", "(c"), Is.EqualTo(1));
}
[Test]
public void Can_RemoveRangeFromSortedSetBySearch()
{
var removed = Redis.RemoveRangeFromSortedSetBySearch("zset", "[aaa", "(g");
Assert.That(removed, Is.EqualTo(5));
var remainder = Redis.SearchSortedSet("zset");
Assert.That(remainder, Is.EqualTo(new[] { "a", "g" }));
}
}
}