public void Remove_BeforeAdd_HasNoEffect(LWW_SetElement <TestType> element) { var lwwSet = new LWW_Set <TestType>(); var newLwwSet = lwwSet.Remove(element.Value, element.Timestamp); Assert.Same(lwwSet, newLwwSet); }
public void Add_AddsElementToAddsSet(LWW_SetElement <TestType> element) { var lwwSet = new LWW_Set <TestType>(); lwwSet = lwwSet.Assign(element.Value, element.Timestamp); Assert.Contains(element, lwwSet.Adds); }
public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value, long timestamp) { var lwwSet = new LWW_Set <TestType>(); lwwSet = lwwSet.Assign(value, timestamp); var lookup = lwwSet.Lookup(value); Assert.True(lookup); }
public void Lookup_AddedAndNotRemoved_ReturnsTrue(LWW_SetElement <TestType> element) { var lwwSet = new LWW_Set <TestType>(); lwwSet = lwwSet.Merge(new[] { element }.ToImmutableHashSet(), ImmutableHashSet <LWW_SetElement <TestType> > .Empty); var lookup = lwwSet.Lookup(element.Value); Assert.True(lookup); }
public void Remove_RemovesElementToRemovesSet(TestType value) { var lwwSet = new LWW_Set <TestType>(); var add = new LWW_SetElement <TestType>(value, DateTime.Now.Ticks); var remove = new LWW_SetElement <TestType>(value, DateTime.Now.AddMinutes(1).Ticks); lwwSet = lwwSet.Assign(add.Value, add.Timestamp); lwwSet = lwwSet.Remove(remove.Value, remove.Timestamp); Assert.Contains(remove, lwwSet.Removes); }
public void Add_ConcurrentAdds_AddsOnlyOne(TestType value, long timestamp) { var lwwSet = new LWW_Set <TestType>(); var firstAdd = new LWW_SetElement <TestType>(value, timestamp); var secondAdd = new LWW_SetElement <TestType>(value, timestamp); lwwSet = lwwSet.Assign(firstAdd.Value, firstAdd.Timestamp); lwwSet = lwwSet.Assign(secondAdd.Value, secondAdd.Timestamp); Assert.Equal(1, lwwSet.Adds.Count(e => Equals(e.Value, value))); }
public void Add_AddSameElementTwiceWithDifferentTimestamp_UpdatesExistingElement(TestType value) { var lwwSet = new LWW_Set <TestType>(); var firstAdd = new LWW_SetElement <TestType>(value, DateTime.Now.Ticks); var secondAdd = new LWW_SetElement <TestType>(value, DateTime.Now.AddMinutes(1).Ticks); lwwSet = lwwSet.Assign(firstAdd.Value, firstAdd.Timestamp); lwwSet = lwwSet.Assign(secondAdd.Value, secondAdd.Timestamp); Assert.True(lwwSet.Adds.Count(e => Equals(e, secondAdd)) == 1); Assert.True(lwwSet.Adds.Count(e => Equals(e, firstAdd)) == 0); }
public void Lookup_AddedAndRemoved_ReturnsFalse(TestType value, long timestamp) { var lwwSet = new LWW_Set <TestType>(); var add = new LWW_SetElement <TestType>(value, timestamp); var remove = new LWW_SetElement <TestType>(value, timestamp + 10); lwwSet = lwwSet.Merge(new[] { add }.ToImmutableHashSet(), new[] { remove }.ToImmutableHashSet()); var lookup = lwwSet.Lookup(value); Assert.False(lookup); }
public void Lookup_AddedAndRemoved_ReturnsFalse(TestType value, long timestamp) { var lwwSet = new LWW_Set <TestType>(); var add = new LWW_SetElement <TestType>(value, timestamp); var remove = new LWW_SetElement <TestType>(value, timestamp + 10); lwwSet = lwwSet.Assign(add.Value, add.Timestamp); lwwSet = lwwSet.Remove(remove.Value, remove.Timestamp); var lookup = lwwSet.Lookup(value); Assert.False(lookup); }
public void Remove_ConcurrentRemoves_AddsOnlyOne(TestType value, long timestamp) { var lwwSet = new LWW_Set <TestType>(); var add = new LWW_SetElement <TestType>(value, timestamp); var firstRemove = new LWW_SetElement <TestType>(value, timestamp + 100); var secondRemove = new LWW_SetElement <TestType>(value, timestamp + 100); lwwSet = lwwSet.Assign(add.Value, add.Timestamp); lwwSet = lwwSet.Remove(firstRemove.Value, firstRemove.Timestamp); lwwSet = lwwSet.Remove(secondRemove.Value, secondRemove.Timestamp); Assert.Equal(1, lwwSet.Removes.Count(e => Equals(e.Value, value))); }
public void Remove_RemoveSameElementTwiceWithDifferentTimestamp_AddsOneElement(TestType value) { var lwwSet = new LWW_Set <TestType>(); var add = new LWW_SetElement <TestType>(value, DateTime.Now.Ticks); var firstRemove = new LWW_SetElement <TestType>(value, DateTime.Now.AddMinutes(1).Ticks); var secondRemove = new LWW_SetElement <TestType>(value, DateTime.Now.AddMinutes(2).Ticks); lwwSet = lwwSet.Assign(add.Value, add.Timestamp); lwwSet = lwwSet.Remove(firstRemove.Value, firstRemove.Timestamp); lwwSet = lwwSet.Remove(secondRemove.Value, secondRemove.Timestamp); Assert.True(lwwSet.Removes.Count(e => Equals(e.Value, value)) == 1); }
public void Merge_MergesAddsAndRemoves(LWW_SetElement <TestType> one, LWW_SetElement <TestType> two, LWW_SetElement <TestType> three, LWW_SetElement <TestType> four, LWW_SetElement <TestType> five) { var lwwSet = new LWW_Set <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); }
public void Create_CreatesSetWithElements(LWW_SetElement <TestType> one, LWW_SetElement <TestType> two, LWW_SetElement <TestType> three) { var adds = new[] { one, two }.ToImmutableHashSet(); var removes = new[] { two, three }.ToImmutableHashSet(); var lwwSet = new LWW_Set <TestType>(adds, removes); Assert.Equal(adds.Count, lwwSet.Adds.Count); Assert.Equal(removes.Count, lwwSet.Removes.Count); foreach (var add in adds) { Assert.Contains(add, lwwSet.Adds); } foreach (var remove in removes) { Assert.Contains(remove, lwwSet.Removes); } }