コード例 #1
0
        public void CountedSetTryGetCountReturnsFalseIfItemIsNotPresent()
        {
            var set = new CountedSet <string>();

            bool result = set.TryGetCount("foo", out _);

            Assert.IsFalse(result);
        }
コード例 #2
0
        public void CountedSetTryGetCountReturnsZeroIfItemIsNotPresent()
        {
            var set = new CountedSet <string>();

            int count;

            Assert.IsFalse(set.TryGetCount("foo", out count));
            Assert.AreEqual(0, count);
        }
コード例 #3
0
        public void IfItemIsAddedToSetMultipleTimesRemoveReducesCountByOne()
        {
            int firstCount  = 0;
            int secondCount = 0;
            var set         = new CountedSet <string>();

            set.Add("foo");
            set.Add("foo");

            set.TryGetCount("foo", out firstCount);

            set.Remove("foo");

            set.TryGetCount("foo", out secondCount);

            Assert.AreEqual(2, firstCount);
            Assert.AreEqual(1, secondCount);
        }
コード例 #4
0
        public void IfItemIsAddedToSetOnceAssociatedCountIsOne()
        {
            int count = 0;
            var set   = new CountedSet <string>();

            set.Add("foo");
            set.TryGetCount("foo", out count);

            Assert.AreEqual(1, count);
        }
コード例 #5
0
        public void CountedSetMaintainsDistinctCountForDifferentItems()
        {
            int fooCount = 0;
            int barCount = 0;

            var set = new CountedSet <string>();

            set.Add("foo");
            set.Add("foo");
            set.Add("foo");
            set.Add("bar");
            set.Add("bar");

            set.TryGetCount("foo", out fooCount);
            set.TryGetCount("bar", out barCount);

            Assert.AreEqual(3, fooCount);
            Assert.AreEqual(2, barCount);
        }
コード例 #6
0
        public void IfItemIsAddedToSetMultipleTimesAssociatedCountIsIncreasedByOne()
        {
            int firstCount  = 0;
            int secondCount = 0;
            int thirdCount  = 0;

            var set = new CountedSet <string>();

            //add first time
            set.Add("foo");
            set.TryGetCount("foo", out firstCount);

            //add second time
            set.Add("foo");
            set.TryGetCount("foo", out secondCount);

            //add third time
            set.Add("foo");
            set.TryGetCount("foo", out thirdCount);

            Assert.AreEqual(1, firstCount);
            Assert.AreEqual(2, secondCount);
            Assert.AreEqual(3, thirdCount);
        }