Пример #1
0
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

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

            lwwSet = lwwSet.Merge(new[] { element }.ToImmutableHashSet(), ImmutableHashSet <LWW_SetWithVCElement <TestType> > .Empty);

            var lookup = lwwSet.Lookup(value);

            Assert.True(lookup);
        }
Пример #2
0
        public void Lookup_AddedAndRemoved_ReturnsFalse(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)));

            lwwSet = lwwSet.Merge(new[] { add }.ToImmutableHashSet(), new[] { remove }.ToImmutableHashSet());

            var lookup = lwwSet.Lookup(value);

            Assert.False(lookup);
        }
Пример #3
0
        public void Merge_MergesAddsAndRemoves(LWW_SetWithVCElement <TestType> one, LWW_SetWithVCElement <TestType> two, LWW_SetWithVCElement <TestType> three, LWW_SetWithVCElement <TestType> four, LWW_SetWithVCElement <TestType> five)
        {
            var lwwSet = new LWW_SetWithVC <TestType>(new[] { one, two }.ToImmutableHashSet(), new[] { three }.ToImmutableHashSet());

            var newLwwSet = lwwSet.Merge(new[] { three, four }.ToImmutableHashSet(), new[] { five }.ToImmutableHashSet());

            Assert.Equal(4, newLwwSet.Adds.Count);
            Assert.Equal(2, newLwwSet.Removes.Count);
            Assert.Contains(one, newLwwSet.Adds);
            Assert.Contains(two, newLwwSet.Adds);
            Assert.Contains(three, newLwwSet.Adds);
            Assert.Contains(four, newLwwSet.Adds);
            Assert.Contains(three, newLwwSet.Removes);
            Assert.Contains(five, newLwwSet.Removes);
        }