Exemplo n.º 1
0
        public void SearchCursor()
        {
            var one   = "one";
            var two   = "two";
            var three = "three";

            var set = new StringSet(4);

            // pretend that we have some hash collisions
            var hash = StringHash.GetHash(one);

            set.Add(one, hash);
            set.Add(two, hash);
            set.Add(three, hash);

            var cursor = set.GetSearchCursor(hash);

            // add one more with the same hash to make sure the cursor doesn't change
            set.Add("four", hash);

            Assert.AreEqual(4, set.Count);
            Assert.AreEqual(4, set.MaxSize); // hash collisions shouldn't cause the set to grow

            Assert.True(cursor.MightHaveMore);
            Assert.AreSame(three, cursor.NextString());
            Assert.True(cursor.MightHaveMore);
            Assert.AreSame(two, cursor.NextString());
            Assert.True(cursor.MightHaveMore);
            Assert.AreSame(one, cursor.NextString());
            Assert.False(cursor.MightHaveMore);
        }