コード例 #1
0
        public void RemoveReturnsFalseIfSetDoesNotContainItem()
        {
            var  set    = new CountedSet <string>();
            bool result = set.Remove("foo");

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

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

            Assert.IsFalse(set.Contains("foo"));
        }
コード例 #3
0
        public void IfItemIsAddedToSetMultipleTimesRemoveDoesNotCompletelyRemoveItem()
        {
            var set = new CountedSet <string>();

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

            Assert.IsTrue(set.Contains("foo"));
        }
コード例 #4
0
        public void IfItemIsAddedToSetMutlipleTimesItMustBeRemovedAnEqualNumberOfTimes()
        {
            bool firstCheck  = false;
            bool secondCheck = false;
            bool thirdCheck  = false;

            var set = new CountedSet <string>();

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

            set.Remove("foo");
            firstCheck = set.Contains("foo");
            set.Remove("foo");
            secondCheck = set.Contains("foo");
            set.Remove("foo");
            thirdCheck = set.Contains("foo");

            Assert.IsTrue(firstCheck);
            Assert.IsTrue(secondCheck);
            Assert.IsFalse(thirdCheck);
        }
コード例 #5
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);
        }