Пример #1
0
        public void ImmutableIntRelationBasics()
        {
            var rel = ImmutableRelations.Create(
                EqualityComparer <int> .Default,
                EqualityComparer <int> .Default);

            rel = rel.Add((1, 2)).Add((1, 3)).Add((2, 3));

            var items = rel.Find(default(int?), default(int?));

            Assert.IsTrue(SetBasedEquals(items, (1, 2), (1, 3), (2, 3)));

            items = rel.Find((int?)1, default(int?));
            Assert.IsTrue(SetBasedEquals(items, (1, 2), (1, 3)));

            items = rel.Find(default(int?), (int?)3);
            Assert.IsTrue(SetBasedEquals(items, (1, 3), (2, 3)));

            items = rel.Find((int?)1, (int?)3);
            Assert.IsTrue(SetBasedEquals(items, (1, 3)));

            items = rel.Find((int?)1, (int?)4);
            Assert.IsFalse(items.Any());

            var rel2 = rel.Add((1, 2));

            Assert.AreEqual(rel2, rel);

            rel   = rel.Add((17, 18));
            items = rel;
            Assert.IsTrue(SetBasedEquals(items, (1, 2), (1, 3), (2, 3), (17, 18)));

            rel   = rel.Add((17, 18));
            items = rel;
            Assert.IsTrue(SetBasedEquals(items, (1, 2), (1, 3), (2, 3), (17, 18)));

            rel   = rel.Add((273, 274));
            items = rel;
            Assert.IsTrue(SetBasedEquals(items, (1, 2), (1, 3), (2, 3), (17, 18), (273, 274)));

            rel2 = rel.Add((273, 274));
            Assert.AreEqual(rel2, rel);

            rel2 = rel.Remove((17, 18));
            Assert.AreNotEqual(rel2, rel);
            rel = rel2;
            Assert.IsTrue(SetBasedEquals(rel, (1, 2), (1, 3), (2, 3), (273, 274)));

            rel = rel.Remove((4, 4));
            Assert.IsTrue(SetBasedEquals(rel, (1, 2), (1, 3), (2, 3), (273, 274)));

            rel = rel.Remove((int?)1, default(int?));
            Assert.IsTrue(SetBasedEquals(rel, (2, 3), (273, 274)));

            rel = rel.Remove(default(int?), (int?)3);
            Assert.IsTrue(SetBasedEquals(rel, (273, 274)));

            rel = rel.Remove(default(int?), default(int?));
            Assert.IsFalse(rel.Any());
        }
Пример #2
0
        public void ImmutableIntRelationBulk()
        {
            var rel = ImmutableRelations.Create(
                EqualityComparer <int> .Default,
                EqualityComparer <int> .Default);

            rel = rel.Bulk(_ => _.Add((1, 2)).Add((1, 3)).Add((2, 3)).Add((17, 18)).Add((273, 274)));

            Assert.AreEqual(5, rel.Count);
            var items = rel.Find(default(int?), default(int?));

            Assert.IsTrue(SetBasedEquals(items, (1, 2), (1, 3), (2, 3), (17, 18), (273, 274)));

            var rel1 = rel.Remove((273, 274));

            Assert.AreEqual(4, rel1.Count);
            Assert.AreEqual(5, rel.Count);
            Assert.IsTrue(SetBasedEquals(rel, (1, 2), (1, 3), (2, 3), (17, 18), (273, 274)));
            Assert.IsTrue(SetBasedEquals(rel1, (1, 2), (1, 3), (2, 3), (17, 18)));

            rel1 = rel.Bulk(_ => _.Remove(default(int?), default(int?)));
            Assert.AreEqual(0, rel1.Count);
            Assert.AreEqual(5, rel.Count);
            Assert.IsTrue(rel1.IsEmpty);
            Assert.IsTrue(SetBasedEquals(rel, (1, 2), (1, 3), (2, 3), (17, 18), (273, 274)));

            rel1 = rel.Add((1, 1));
            Assert.AreEqual(6, rel1.Count);
            Assert.AreEqual(5, rel.Count);
            Assert.IsTrue(SetBasedEquals(rel, (1, 2), (1, 3), (2, 3), (17, 18), (273, 274)));
            Assert.IsTrue(SetBasedEquals(rel1, (1, 1), (1, 2), (1, 3), (2, 3), (17, 18), (273, 274)));
        }
Пример #3
0
        public void ImmutableObjectRelationBasics()
        {
            var rel = ImmutableRelations.Create(
                EqualityComparer <Key> .Default,
                EqualityComparer <Key> .Default);

            var o1   = new Key(1);
            var o2   = new Key(2);
            var o3   = new Key(3);
            var o17  = new Key(17);
            var o18  = new Key(18);
            var o257 = new Key(257);
            var o258 = new Key(258);
            var o513 = new Key(513);
            var o514 = new Key(514);

            rel = rel.Add((o1, o2)).Add((o1, o3)).Add((o2, o3));

            var items = rel.Find(default, default);