public void SymmetricExceptInvokesChange() { var hashMap = AtomHashMap <TString, string, int>( ("foo", 3), ("bar", 42)); var toExcept = AtomHashMap <TString, string, int>( ("foo", 3), ("biz", 7), ("baz", 9)); var initialValue = hashMap.ToHashMap(); HashMapPatch <TString, string, int> state = default; hashMap.Change += v => state = v; hashMap.SymmetricExcept(toExcept); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( initialValue.SymmetricExcept(toExcept), hashMap.ToHashMap()); Assert.Equal( HashMap( ("foo", Change <int> .Removed(3)), ("biz", Change <int> .Added(7)), ("baz", Change <int> .Added(9))), state.Changes); }
public void UnionInvokesChange() { var hashMap = AtomHashMap <TString, string, int>( ("foo", 3), ("bar", 42)); var toUnion = AtomHashMap <TString, string, int>( ("foo", 7), ("biz", 7), ("baz", 9)); var initialValue = hashMap.ToHashMap(); HashMapPatch <TString, string, int> state = default; hashMap.Change += v => state = v; hashMap.Union(toUnion); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( initialValue.Union(toUnion), hashMap.ToHashMap()); Assert.Equal( HashMap( ("foo", Change <int> .Mapped(3, 7)), ("biz", Change <int> .Added(7)), ("baz", Change <int> .Added(9))), state.Changes); }
public void SwapInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.Swap(m => m.Add("biz", 99)); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap(("biz", Change <int> .Added(99))), state.Changes); }
public void SwapKeyOptionalInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.SwapKey("foo", i => None); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap(("foo", Change <int> .Removed(3))), state.Changes); }
public void SwapKeyInvokesChange() { var hashMap = AtomHashMap <TString, string, int>( ("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <TString, string, int> state = default; hashMap.Change += v => state = v; hashMap.SwapKey("foo", i => i + 1); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap(("foo", Change <int> .Mapped(3, 4))), state.Changes); }
public void TrySetItemFuncInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.TrySetItem("foo", i => i * 2); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("foo", Change <int> .Mapped(3, 6))), state.Changes); }
public void FindOrMaybeAddConstantInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.FindOrMaybeAdd("biz", Some(7)); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("biz", Change <int> .Added(7))), state.Changes); }
public void RemoveInvokesChange() { var hashMap = AtomHashMap <TString, string, int>( ("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <TString, string, int> state = default; hashMap.Change += v => state = v; hashMap.Remove("bar"); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("bar", Change <int> .Removed(42))), state.Changes); }
public void FilterInPlaceWithKeyInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42), ("biz", 7)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.FilterInPlace((k, i) => k[0] == 'b' && i % 2 == 0); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("foo", Change <int> .Removed(3)), ("biz", Change <int> .Removed(7))), state.Changes); }
public void TrySetItemsInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.TrySetItems(Seq(("foo", 80), ("bar", 17), ("biz", 33))); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("foo", Change <int> .Mapped(3, 80)), ("bar", Change <int> .Mapped(42, 17))), state.Changes); }
public void AddOrUpdateRangeInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.AddOrUpdateRange(Seq(("biz", 7), ("baz", 9))); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("biz", Change <int> .Added(7)), ("baz", Change <int> .Added(9))), state.Changes); }
public void MapInPlaceInvokesChange() { var hashMap = AtomHashMap(("foo", 3), ("bar", 42), ("biz", 7)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.MapInPlace(i => i * 3); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( HashMap( ("foo", Change <int> .Mapped(3, 9)), ("bar", Change <int> .Mapped(42, 126)), ("biz", Change <int> .Mapped(7, 21))), state.Changes); }
public void IntersectAtomInvokesChange() { var hashMap = AtomHashMap <TString, string, int>( ("foo", 3), ("bar", 42), ("biz", 7), ("baz", 9)); var toIntersect = AtomHashMap <TString, string, int>( ("foo", 7), ("biz", 7), ("baz", 9), ("bin", 0)); var initialValue = hashMap.ToHashMap(); HashMapPatch <TString, string, int> state = default; hashMap.Change += v => state = v; hashMap.Intersect(toIntersect); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( initialValue.Intersect(toIntersect.ToHashMap()), hashMap.ToHashMap()); Assert.Equal( HashMap( ("bar", Change <int> .Removed(42))), state.Changes); }
public void ExceptKeysInvokesChange() { var hashMap = AtomHashMap( ("foo", 3), ("bar", 42), ("biz", 7), ("baz", 9)); var toExcept = Seq("biz", "baz"); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.Except(toExcept); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( initialValue.Except(toExcept), hashMap.ToHashMap()); Assert.Equal( HashMap( ("biz", Change <int> .Removed(7)), ("baz", Change <int> .Removed(9))), state.Changes); }
public void SubtractAtomInvokesChange() { var hashMap = AtomHashMap( ("foo", 3), ("bar", 42), ("biz", 7), ("baz", 9)); var toSubtract = AtomHashMap(("foo", 7), ("biz", 7), ("baz", 9)); var initialValue = hashMap.ToHashMap(); HashMapPatch <string, int> state = default; hashMap.Change += v => state = v; hashMap.Subtract(toSubtract); Assert.Equal(initialValue, state.From); Assert.Equal(hashMap.ToHashMap(), state.To); Assert.Equal( initialValue.Subtract(toSubtract.ToHashMap()), hashMap.ToHashMap()); Assert.Equal( HashMap( ("foo", Change <int> .Removed(3)), ("biz", Change <int> .Removed(7)), ("baz", Change <int> .Removed(9))), state.Changes); }