Exemple #1
0
        public void LookupGetWhenPresent()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.Lookup <int, string>(1);

            Assert.AreSame("A", dict.Get(elementLens).Value);
        }
Exemple #2
0
        public void ByKeyGetWhenNotPresent()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.ByKey <int, string>(2);

            dict.Get(elementLens);
        }
Exemple #3
0
        public void LookupGetWhenNotPresent()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.Lookup <int, string>(2);

            Assert.AreSame(Maybe <string> .None, dict.Get(elementLens));
        }
Exemple #4
0
        public void LookupGetDefaultedWhenPresent()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.Lookup(1, x => "B");

            Assert.AreSame("A", dict.Get(elementLens));
        }
Exemple #5
0
        public void LookupSetNothingRemovesEntry()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.Lookup <int, string>(1);

            var updated = dict.Set(elementLens, Maybe <string> .None);

            Assert.IsFalse(updated.Any());
        }
Exemple #6
0
        public void ByKeySetUpdatesEntry()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.ByKey <int, string>(1);

            var updated = dict.Set(elementLens, "B");

            Assert.AreEqual(1, updated.Count());
            Assert.AreEqual("B", updated[1]);
        }
Exemple #7
0
        public void LookupSetDefaultedUpdatesEntry()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.Lookup(1, x => "C");

            var updated = dict.Set(elementLens, "B");

            Assert.AreEqual(1, updated.Count());
            Assert.AreEqual("B", updated[1]);
        }
Exemple #8
0
        public void LookupSetAddsEntry()
        {
            var dict = ImmutableDictionary <int, string> .Empty.Add(1, "A");

            var elementLens = ImmutableDictionaryLens.Lookup <int, string>(2);

            var updated = dict.Set(elementLens, "B".ToMaybe());

            Assert.AreEqual(2, updated.Count());
            Assert.AreEqual("A", updated[1]);
            Assert.AreEqual("B", updated[2]);
        }