/usr/share/gocode/src/github.com/alicebob/miniredis/sorted_set_test.go is in golang-github-alicebob-miniredis-dev 2.2.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | package miniredis
import (
"testing"
)
func TestSortedSetImpl(t *testing.T) {
s := newSortedSet()
equals(t, 0, s.card())
s.set(3.1415, "pi")
s.set(2*3.1415, "2pi")
s.set(3*3.1415, "3pi")
equals(t, 3, s.card())
// replace works?
s.set(3.141592, "pi")
equals(t, 3, s.card())
// Get a key
{
pi, ok := s.get("pi")
assert(t, ok, "got pi")
equals(t, 3.141592, pi)
}
// Set ordered by score
{
elems := s.byScore(asc)
equals(t, 3, len(elems))
equals(t, ssElems{
{3.141592, "pi"},
{2 * 3.1415, "2pi"},
{3 * 3.1415, "3pi"},
}, elems)
}
// Rank of a key
{
rank, found := s.rankByScore("pi", asc)
assert(t, found, "Found pi")
equals(t, 0, rank)
rank, found = s.rankByScore("3pi", desc)
assert(t, found, "Found 3pi")
equals(t, 0, rank)
rank, found = s.rankByScore("3pi", asc)
assert(t, found, "Found 3pi")
equals(t, 2, rank)
_, found = s.rankByScore("nosuch", asc)
assert(t, !found, "Did not find nosuch")
}
}
func TestSortOrder(t *testing.T) {
// Keys with the same key should be sorted lexicographically
s := newSortedSet()
equals(t, 0, s.card())
s.set(1, "one")
s.set(1, "1")
s.set(1, "eins")
s.set(2, "two")
s.set(2, "2")
s.set(2, "zwei")
s.set(3, "three")
s.set(3, "3")
s.set(3, "drei")
equals(t, 9, s.card())
// Set ordered by score, member
{
elems := s.byScore(asc)
equals(t, 9, len(elems))
equals(t, ssElems{
{1, "1"},
{1, "eins"},
{1, "one"},
{2, "2"},
{2, "two"},
{2, "zwei"},
{3, "3"},
{3, "drei"},
{3, "three"},
}, elems)
}
}
|