Example #1
0
        public void SimpleValueTests()
        {
            Set<int> empty = new Set<int>();
            Set<int> a = new Set<int>(1, 2, 3);
            Set<int> b = new Set<int>(3, 4, 5);

            Set<int> a_and_b = a + b;

            Assert.AreEqual("{}", empty.ToString());
            Assert.AreEqual("{ 1, 2, 3 }", a.ToString());
            Assert.AreEqual("{ 3, 4, 5 }", b.ToString());

            Assert.AreEqual("{ 1, 2, 3, 4, 5 }", a_and_b.ToString());

            Assert.AreEqual("{}", (empty * a).ToString());
            Assert.AreEqual("{}", (a * empty).ToString());

            Assert.IsTrue(a_and_b * a == a);
            Assert.IsTrue((a_and_b * a).Equals(a));

            Assert.IsTrue(a_and_b - a == new Set<int>(4, 5));
            Assert.IsTrue(a - a == new Set<int>());
            Assert.IsTrue(a * a == a);

            Assert.IsTrue(a.IsSubsetOf(a_and_b));
            Assert.IsTrue(b.IsSubsetOf(a_and_b));
            Assert.IsTrue(a_and_b.IsSubsetOf(a_and_b));

            Assert.IsTrue(a.IsSubsetOf(a));
            Assert.IsTrue(b.IsSubsetOf(b));

            Assert.IsFalse(a.IsSubsetOf(b));
            Assert.IsFalse(b.IsSubsetOf(a));
            Assert.IsFalse(a_and_b.IsSubsetOf(a));
            Assert.IsFalse(a_and_b.IsSubsetOf(b));

            Set<int> a_copy = a.Copy();
            Set<int> b_copy = b.Copy();

            a.UnionUpdate(b);
            Assert.AreEqual(a, a_and_b);

            a.DifferenceUpdate(b);
            Assert.AreEqual(a, a_and_b - b);

            a.UnionUpdate(9);
            Assert.AreEqual(a, (a_and_b - b) + new Set<int>(9));

            a.DifferenceUpdate(1);
            Assert.AreEqual(a, (a_and_b - b) + new Set<int>(9) - new Set<int>(1));

            a_copy.IntersectionUpdate(b_copy);
            Assert.AreEqual(new Set<int>(3), a_copy);
        }