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 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);
        }
示例#3
0
        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);
        }
示例#4
0
        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 AddOrUpdateInvokesChange()
        {
            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.AddOrUpdate("biz", 7);

            Assert.Equal(initialValue, state.From);
            Assert.Equal(hashMap.ToHashMap(), state.To);
            Assert.Equal(
                HashMap(
                    ("biz", Change <int> .Added(7))),
                state.Changes);
        }
示例#6
0
        public void AppendInvokesChange()
        {
            var hashMap      = AtomHashMap(("foo", 3), ("bar", 42));
            var toAppend     = HashMap(("foo", 7), ("biz", 7), ("baz", 9));
            var initialValue = hashMap.ToHashMap();
            HashMapPatch <string, int> state = default;

            hashMap.Change += v => state = v;

            hashMap.Append(toAppend);

            Assert.Equal(initialValue, state.From);
            Assert.Equal(hashMap.ToHashMap(), state.To);
            Assert.Equal(initialValue.Append(toAppend), hashMap.ToHashMap());
            Assert.Equal(
                HashMap(
                    ("biz", Change <int> .Added(7)),
                    ("baz", Change <int> .Added(9))),
                state.Changes);
        }