public void Add_ConcurrentAdds_AddsOnlyOne(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var firstAdd  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var secondAdd = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));

            lwwSet = lwwSet.Assign(firstAdd.Value, firstAdd.VectorClock);
            lwwSet = lwwSet.Assign(secondAdd.Value, secondAdd.VectorClock);

            Assert.Equal(1, lwwSet.Adds.Count(e => Equals(e.Value, value)));
        }
        public void Add_AddSameElementTwiceWithDifferentTimestamp_UpdatesExistingElement(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var firstAdd  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var secondAdd = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));

            lwwSet = lwwSet.Assign(firstAdd.Value, firstAdd.VectorClock);
            lwwSet = lwwSet.Assign(secondAdd.Value, secondAdd.VectorClock);

            Assert.True(lwwSet.Adds.Count(e => Equals(e, secondAdd)) == 1);
            Assert.True(lwwSet.Adds.Count(e => Equals(e, firstAdd)) == 0);
        }
        public void Lookup_ReAdded_ReturnsTrue(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add    = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var remove = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));
            var reAdd  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 2)));

            lwwSet = lwwSet.Assign(add.Value, add.VectorClock);
            lwwSet = lwwSet.Remove(remove.Value, remove.VectorClock);
            lwwSet = lwwSet.Assign(reAdd.Value, reAdd.VectorClock);

            var lookup = lwwSet.Lookup(value);

            Assert.True(lookup);
        }
        public void Add_AddsElementToAddsSet(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));

            lwwSet = lwwSet.Assign(add.Value, add.VectorClock);

            Assert.Contains(add, lwwSet.Adds);
        }
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            lwwSet = lwwSet.Assign(value, new VectorClock(clock.Add(node, 0)));

            var lookup = lwwSet.Lookup(value);

            Assert.True(lookup);
        }
        public void Remove_RemoveSameElementTwiceWithDifferentTimestamp_AddsOneElement(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add          = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var firstRemove  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));
            var secondRemove = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 2)));

            lwwSet = lwwSet.Assign(add.Value, add.VectorClock);
            lwwSet = lwwSet.Remove(firstRemove.Value, firstRemove.VectorClock);
            lwwSet = lwwSet.Remove(secondRemove.Value, secondRemove.VectorClock);

            Assert.True(lwwSet.Removes.Count(e => Equals(e.Value, value)) == 1);
        }