예제 #1
0
        public void ConsOnIPersistentMapAddsOrReplacesMany()
        {
            Dictionary <int, string> d1 = new Dictionary <int, string>();

            d1[1] = "a";
            d1[2] = "b";

            IPersistentMap m1 = PersistentArrayMap.create(d1);


            Dictionary <int, string> d2 = new Dictionary <int, string>();

            d2[2] = "c";
            d2[3] = "d";

            IPersistentMap m2 = PersistentArrayMap.create(d2);
            IPersistentMap m3 = m1.cons(m2);


            Expect(m1.count(), EqualTo(2));
            Expect(m1.valAt(1), EqualTo("a"));
            Expect(m1.valAt(2), EqualTo("b"));

            Expect(m2.count(), EqualTo(2));
            Expect(m2.valAt(2), EqualTo("c"));
            Expect(m2.valAt(3), EqualTo("d"));

            Expect(m3.count(), EqualTo(3));
            Expect(m3.valAt(1), EqualTo("a"));
            Expect(m3.valAt(2), EqualTo("c"));
            Expect(m3.valAt(3), EqualTo("d"));
        }
예제 #2
0
        public void ConsOnNon2IPVFails()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);

            IPersistentVector v = PersistentVector.create(2, "c", 3, "d");
            IPersistentMap    c = m.cons(v);
        }
예제 #3
0
        public void ConsOnKeyValuePairReplacesExisting()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);
            IPersistentMap c = m.cons(new KeyValuePair <int, string>(2, "c"));

            Expect(m.count(), EqualTo(2));
            Expect(m.valAt(1), EqualTo("a"));
            Expect(m.valAt(2), EqualTo("b"));

            Expect(c.count(), EqualTo(2));
            Expect(c.valAt(1), EqualTo("a"));
            Expect(c.valAt(2), EqualTo("c"));
        }
예제 #4
0
        public void ConsOnDictionaryEntryReplacesExisting()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);
            IPersistentMap c = m.cons(new DictionaryEntry(2, "c"));

            Expect(m.count()).To.Equal(2);
            Expect(m.valAt(1)).To.Equal("a");
            Expect(m.valAt(2)).To.Equal("b");

            Expect(c.count()).To.Equal(2);
            Expect(c.valAt(1)).To.Equal("a");
            Expect(c.valAt(2)).To.Equal("c");
        }
예제 #5
0
        public void ConsOnDictionaryEntryAddsNew()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);
            IPersistentMap c = m.cons(new DictionaryEntry(3, "c"));

            Expect(m.count(), EqualTo(2));
            Expect(m.valAt(1), EqualTo("a"));
            Expect(m.valAt(2), EqualTo("b"));

            Expect(c.count(), EqualTo(3));
            Expect(c.valAt(1), EqualTo("a"));
            Expect(c.valAt(2), EqualTo("b"));
            Expect(c.valAt(3), EqualTo("c"));
        }
예제 #6
0
        public void ConsOnKeyValuePairAddsNew()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);
            IPersistentMap c = m.cons(new KeyValuePair <int, string>(3, "c"));

            Expect(m.count()).To.Equal(2);
            Expect(m.valAt(1)).To.Equal("a");
            Expect(m.valAt(2)).To.Equal("b");

            Expect(c.count()).To.Equal(3);
            Expect(c.valAt(1)).To.Equal("a");
            Expect(c.valAt(2)).To.Equal("b");
            Expect(c.valAt(3)).To.Equal("c");
        }