Пример #1
0
        public void Remove_BeforeAdd_HasNoEffect(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            var newPSet = pSet.Remove(value);

            Assert.Same(pSet, newPSet);
        }
Пример #2
0
        public void Add_Concurrent_AddsOnlyOneElement(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            pSet = pSet.Add(value);
            pSet = pSet.Add(value);

            Assert.Equal(1, pSet.Elements.Count(v => Equals(v.Value, value)));
        }
Пример #3
0
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            pSet = pSet.Merge(new[] { new P_OptimizedSetElement <TestType>(value, false) }.ToImmutableHashSet());

            var lookup = pSet.Lookup(value);

            Assert.True(lookup);
        }
Пример #4
0
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            pSet = pSet.Add(value);

            var lookup = pSet.Lookup(value);

            Assert.True(lookup);
        }
Пример #5
0
        public void Add_AddsElementToAddsSet(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            pSet = pSet.Add(value);

            var expectedElement = new P_OptimizedSetElement <TestType>(value, false);

            Assert.Contains(expectedElement, pSet.Elements);
        }
Пример #6
0
        public void Lookup_ReAdded_ReturnsFalse(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            pSet = pSet.Add(value);
            pSet = pSet.Remove(value);
            pSet = pSet.Add(value);

            var lookup = pSet.Lookup(value);

            Assert.False(lookup);
        }
Пример #7
0
        public void Create_CreatesSetWithElements(P_OptimizedSetElement <TestType> one, P_OptimizedSetElement <TestType> two, P_OptimizedSetElement <TestType> three)
        {
            var elements = new[] { one, two, three }.ToImmutableHashSet();

            var pSet = new P_OptimizedSet <TestType>(elements);

            Assert.Equal(elements.Count, pSet.Elements.Count);

            foreach (var add in elements)
            {
                Assert.Contains(add, pSet.Elements);
            }
        }
Пример #8
0
        public void Remove_AddsRemovedFlagToElement(TestType value)
        {
            var pSet = new P_OptimizedSet <TestType>();

            pSet = pSet.Add(value);
            pSet = pSet.Remove(value);

            var expectedElement    = new P_OptimizedSetElement <TestType>(value, true);
            var notExpectedElement = new P_OptimizedSetElement <TestType>(value, false);

            Assert.Contains(expectedElement, pSet.Elements);
            Assert.DoesNotContain(notExpectedElement, pSet.Elements);
        }
Пример #9
0
        public void Merge_MergesAddsAndRemoves(TestType one, TestType two, TestType three)
        {
            var elementOne   = new P_OptimizedSetElement <TestType>(one, false);
            var elementTwo   = new P_OptimizedSetElement <TestType>(two, true);
            var elementThree = new P_OptimizedSetElement <TestType>(one, true);
            var elementFour  = new P_OptimizedSetElement <TestType>(three, false);

            var pSet = new P_OptimizedSet <TestType>(new[] { elementOne, elementTwo }.ToImmutableHashSet());

            var newPSet = pSet.Merge(new[] { elementThree, elementFour }.ToImmutableHashSet());

            Assert.Equal(4, newPSet.Elements.Count);
            Assert.Contains(newPSet.Elements, e => Equals(e, elementOne));
            Assert.Contains(newPSet.Elements, e => Equals(e, elementTwo));
            Assert.Contains(newPSet.Elements, e => Equals(e, elementThree));
            Assert.Contains(newPSet.Elements, e => Equals(e, elementFour));
        }