public void DisjointedSet_Add_ThreeRanges_Overlapped_Inside_Merged()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 20)
            });
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("bob", 30),
                new StackExchange.Redis.SortedSetEntry("derek", 40)
            });

            //One more to merge with the one above
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("carol", 25),
                new StackExchange.Redis.SortedSetEntry("sue", 35)
            });

            Assert.IsNull(set.RetrieveByScore(5, 50, Exclude.None));
            Assert.AreEqual(1, set.RetrieveByScore(20, 20, Exclude.None).Count());
            Assert.AreEqual(3, set.RetrieveByScore(25, 35, Exclude.None).Count());
            Assert.AreEqual(4, set.RetrieveByScore(25, 40, Exclude.None).Count());

            //A set to merge all three
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("emma", 5),
                new StackExchange.Redis.SortedSetEntry("frank", 50)
            });

            Assert.AreEqual(7, set.RetrieveByScore(5, 50, Exclude.None).Count());
        }
        public void DisjointedSet_Add_ThreeRanges_Overlapped_Outside_Merged()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 20)
            });
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("bob", 30),
                new StackExchange.Redis.SortedSetEntry("derek", 40)
            });

            //One more to merge into the two above
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("carol", 10),
                new StackExchange.Redis.SortedSetEntry("sue", 50)
            });

            Assert.IsNull(set.RetrieveByScore(5, 50, Exclude.None));
            Assert.AreEqual(1, set.RetrieveByScore(10, 10, Exclude.None).Count());
            Assert.AreEqual(3, set.RetrieveByScore(15, 45, Exclude.None).Count());
            Assert.AreEqual(5, set.RetrieveByScore(10, 50, Exclude.None).Count());
        }
        public void DisjointedSet_Add_Duplicate_ExcludeBoth()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10) });
            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 20) });
            Assert.IsNull(set.RetrieveByScore(10, 10, Exclude.Both));
            Assert.AreEqual(0, set.RetrieveByScore(20, 20, Exclude.Both).Count());
        }
        public void DisjointedSet_Add_TwoRanges_RetrieveByBoundaries()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10) });
            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("bob", 20) });
            Assert.IsNull(set.RetrieveByScore(10, 20, Exclude.None));
            Assert.AreEqual(1, set.RetrieveByScore(10, 10, Exclude.None).Count());
            Assert.AreEqual(1, set.RetrieveByScore(20, 20, Exclude.None).Count());
        }
        public void DisjointedSet_DuplicateValues_AddedSeparately()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10)
            });
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10)
            });

            Assert.AreEqual(1, set.RetrieveByScore(10, 10, Exclude.None).Count());
        }
        public void DisjointedSet_Add_TwoRanges_Overlapped_Inner_Merged()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10),
                new StackExchange.Redis.SortedSetEntry("carol", 40)
            });
            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("bob", 20),
                new StackExchange.Redis.SortedSetEntry("derek", 30)
            });

            Assert.AreEqual(4, set.RetrieveByScore(10, 40, Exclude.None).Count());
        }
        public void DisjointedSet_Add_OneEntry_ExcludeBoth()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10) });
            var result = set.RetrieveByScore(10, 10, Exclude.Both);

            Assert.AreEqual(0, result.Count());
        }
        public void DisjointedSet_Add_OneRange_TwoEntries_RetrieveByBoundaries()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10),
                            new StackExchange.Redis.SortedSetEntry("bob", 20) });
            var result = set.RetrieveByScore(10, 20, Exclude.None);

            Assert.AreEqual(2, result.Count());
        }
        public void DisjointedSet_Add_OneRange_ManyEntries_RetrieveOutsideLowerBoundary()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10),
                            new StackExchange.Redis.SortedSetEntry("bob", 20),
                            new StackExchange.Redis.SortedSetEntry("carol", 30),
                            new StackExchange.Redis.SortedSetEntry("derek", 40) });
            var result = set.RetrieveByScore(5, 25, Exclude.None);

            Assert.IsNull(result);
        }
        public void DisjointedSet_Add_OneRange_ManyEntries_RetrieveEmptyResult()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10),
                            new StackExchange.Redis.SortedSetEntry("bob", 20),
                            new StackExchange.Redis.SortedSetEntry("carol", 30),
                            new StackExchange.Redis.SortedSetEntry("derek", 40) });
            var result = set.RetrieveByScore(15, 18, Exclude.None);

            Assert.AreEqual(0, result.Count());
        }
        public void DisjointedSortedSet_RetrieveScoreByValue_Simple()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10),
                new StackExchange.Redis.SortedSetEntry("bob", 20)
            });
            Assert.AreEqual(10, set.RetrieveScoreByValue("anna"));
            Assert.IsNull(set.RetrieveScoreByValue("nonexistant"));
        }
        public void SortedSet_AddSingleItems_ThenRange()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("one", 1) });
            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("two", 2) });
            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("three", 3) });

            //Add a range that unites the above
            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("zero", 0),
                new StackExchange.Redis.SortedSetEntry("one", 1),
                new StackExchange.Redis.SortedSetEntry("two", 2),
                new StackExchange.Redis.SortedSetEntry("three", 3),
                new StackExchange.Redis.SortedSetEntry("four", 4)
            });

            Assert.AreEqual(5, set.RetrieveByScore(0, 4, Exclude.None).Count());
            Assert.AreEqual(3, set.RetrieveByScore(0, 4, Exclude.Both).Count());
            Assert.AreEqual(4, set.RetrieveByScore(0, 4, Exclude.Start).Count());
            Assert.AreEqual(4, set.RetrieveByScore(0, 4, Exclude.Stop).Count());
        }
Beispiel #13
0
        public void DisjointedSortedSet_Remove_Simple()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10),
                new StackExchange.Redis.SortedSetEntry("bob", 20)
            });
            Assert.AreEqual(2, set.Count);
            set.Remove(new RedisValue[] { "anna" });
            Assert.AreEqual(1, set.Count);
        }
Beispiel #14
0
        public void DisjointedSortedSet_JoinRanges_Joins_RangesPartiallyMatches()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("zero", 0),
                new StackExchange.Redis.SortedSetEntry("one", 1)
            });
            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("two", 2),
                new StackExchange.Redis.SortedSetEntry("three", 3)
            });
            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("four", 4),
                new StackExchange.Redis.SortedSetEntry("five", 5)
            });

            Assert.IsNull(set.RetrieveByScore(2, 5, Exclude.None));

            set.JoinRanges(new RedisValue[] { "three", "four", "five", "six" });

            Assert.AreEqual(4, set.RetrieveByScore(2, 5, Exclude.None).Count());
        }
        public void DisjointedSortedSet_Sorting_ReceivedReverse_Reverse()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 20),
                new StackExchange.Redis.SortedSetEntry("bob", 10)
            });

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("carol", 25),
                new StackExchange.Redis.SortedSetEntry("derek", 15)
            });

            var result = set.RetrieveByScore(10, 25, Exclude.None);

            Assert.AreEqual(10, result.ElementAt(0).Score);
            Assert.AreEqual(15, result.ElementAt(1).Score);
            Assert.AreEqual(20, result.ElementAt(2).Score);
            Assert.AreEqual(25, result.ElementAt(3).Score);
        }
        public void DisjointedSortedSet_Sorting_Simple()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10),
                new StackExchange.Redis.SortedSetEntry("bob", 20)
            });
            var result = set.RetrieveByScore(10, 20, Exclude.None);

            Assert.AreEqual(10, result.ElementAt(0).Score);
            Assert.AreEqual(20, result.ElementAt(1).Score);
        }
        public void DisjointedSet_Add_OneRange_ManyEntries_RetrieveInsideBoundaries()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] { new StackExchange.Redis.SortedSetEntry("anna", 10),
                            new StackExchange.Redis.SortedSetEntry("bob", 20),
                            new StackExchange.Redis.SortedSetEntry("carol", 30),
                            new StackExchange.Redis.SortedSetEntry("derek", 40) });
            var result = set.RetrieveByScore(19, 31, Exclude.None);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("bob", (string)result.ElementAt(0).Element);
            Assert.AreEqual("carol", (string)result.ElementAt(1).Element);
        }
Beispiel #18
0
        public void DisjointedSortedSet_Remove_InMiddle()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[]
            {
                new StackExchange.Redis.SortedSetEntry("anna", 10),
                new StackExchange.Redis.SortedSetEntry("bob", 20),
                new StackExchange.Redis.SortedSetEntry("carol", 30)
            });
            set.Remove(new RedisValue[] { "bob" });
            var result = set.RetrieveByScore(10, 30, Exclude.None);

            Assert.AreEqual(2, result.Count());
        }
Beispiel #19
0
        public void DisjointedSortedSet_JoinRanges_OutsideExistingRange()
        {
            DisjointedSortedSet set = new DisjointedSortedSet();

            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("zero", 0),
                new StackExchange.Redis.SortedSetEntry("one", 1),
                new StackExchange.Redis.SortedSetEntry("two", 2),
                new StackExchange.Redis.SortedSetEntry("three", 3),
                new StackExchange.Redis.SortedSetEntry("four", 4)
            });

            set.JoinRanges(new RedisValue[] { "four", "five" });

            Assert.AreEqual(5, set.RetrieveByScore(0, 4, Exclude.None).Count());
        }
        public void DisjointedSortedSet_RemoveByScore_ExcludeStop()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("zero", 0),
                new StackExchange.Redis.SortedSetEntry("one", 1),
                new StackExchange.Redis.SortedSetEntry("two", 2)
            });

            Assert.AreEqual(1, set.RetrieveByScore(0, 0, Exclude.None).Count());
            Assert.AreEqual(1, set.RetrieveByScore(1, 1, Exclude.None).Count());
            Assert.AreEqual(1, set.RetrieveByScore(2, 2, Exclude.None).Count());
            set.RemoveByScore(0, 2, Exclude.Stop);
            Assert.IsNull(set.RetrieveByScore(0, 0, Exclude.None));
            Assert.IsNull(set.RetrieveByScore(1, 1, Exclude.None));
            Assert.AreEqual(1, set.RetrieveByScore(2, 2, Exclude.None).Count());
        }
        public void DisjointedSortedSet_RemoveByScore_ExcludeBoth()
        {
            var set = new DisjointedSortedSet();

            set.Add(new[] {
                new StackExchange.Redis.SortedSetEntry("zero", 0),
                new StackExchange.Redis.SortedSetEntry("one", 1),
                new StackExchange.Redis.SortedSetEntry("two", 2)
            });

            Assert.AreEqual(1, set.RetrieveByScore(0, 0, Exclude.None).Count());
            Assert.AreEqual(1, set.RetrieveByScore(1, 1, Exclude.None).Count());
            Assert.AreEqual(1, set.RetrieveByScore(2, 2, Exclude.None).Count());
            set.RemoveByScore(0, 2, Exclude.Both);
            Assert.AreEqual(1, set.RetrieveByScore(0, 0, Exclude.None).Count());
            Assert.IsNotNull(set.RetrieveByScore(1, 1, Exclude.None)); //There is still a valid range of "0, 2", which no longer contains 1. So we know 1 doesn't exist.
            Assert.AreEqual(0, set.RetrieveByScore(1, 1, Exclude.None).Count());
            Assert.AreEqual(1, set.RetrieveByScore(2, 2, Exclude.None).Count());
        }