示例#1
0
        public void TestSize()
        {
            GenericSet <int> gs = new GenericSet <int>();

            Assert.That(gs.Size, Is.EqualTo(0));

            gs.Add(1);
            Assert.That(gs.Size, Is.EqualTo(1));
            gs.Add(2);
            Assert.That(gs.Size, Is.EqualTo(2));
        }
示例#2
0
        public void TestDifference()
        {
            GenericSet <int> gs1 = new GenericSet <int>();

            for (int i = 1; i <= 8; i++)
            {
                gs1.Add(i);
            }
            Console.WriteLine(gs1);

            GenericSet <int> gs2 = new GenericSet <int>();

            for (int i = 5; i <= 15; i++)
            {
                gs2.Add(i);
            }
            Console.WriteLine(gs2);

            GenericSet <int> difference = gs1.Difference(gs2);

            Assert.That(difference.Size, Is.EqualTo(4));
            Assert.That(difference.Contains(15), Is.False);
            Assert.That(difference.Contains(5), Is.False);
            Assert.That(difference.Contains(1), Is.True);
            Assert.That(difference.Contains(4), Is.True);
            Console.WriteLine("Difference: {0}", difference);
        }
示例#3
0
        public void TestIntersection()
        {
            GenericSet <int> gs1 = new GenericSet <int>();

            for (int i = 1; i <= 8; i++)
            {
                gs1.Add(i);
            }
            Console.WriteLine(gs1);

            GenericSet <int> gs2 = new GenericSet <int>();

            for (int i = 5; i <= 15; i++)
            {
                gs2.Add(i);
            }
            Console.WriteLine(gs2);

            GenericSet <int> union = gs1.Intersection(gs2);

            Assert.That(union.Size, Is.EqualTo(4));
            Assert.That(union.Contains(15), Is.False);
            Assert.That(union.Contains(1), Is.False);
            Assert.That(union.Contains(5), Is.True);
            Assert.That(union.Contains(8), Is.True);
            Console.WriteLine("Intersection: {0}", union);
        }
示例#4
0
        public int[] CheckAddExistingElementToSet(int[] array, int element)
        {
            var set = new GenericSet <int>(array);

            Assert.That(set.Add(element), Is.False);
            return(set.ToArray());
        }
示例#5
0
        public void TestIsEmpty()
        {
            GenericSet <int> gs = new GenericSet <int>();

            Assert.That(gs.IsEmpty, Is.True);

            gs.Add(1);
            Assert.That(gs.IsEmpty, Is.False);
        }
示例#6
0
        public void TestContains()
        {
            GenericSet <int> gs = new GenericSet <int>();

            for (int i = 0; i < 10; i++)
            {
                gs.Add(i + 1);
            }
            Assert.That(gs.Contains(5), Is.True);
            Assert.That(gs.Contains(100), Is.False);
        }
示例#7
0
        public void TestEquals()
        {
            GenericSet <int> gs1 = new GenericSet <int>();
            GenericSet <int> gs2 = new GenericSet <int>();

            Assert.That(gs1.Equals(gs2), Is.True);

            for (int i = 1; i <= 5; i++)
            {
                gs1.Add(i);
            }
            Console.WriteLine("set1: {0}", gs1);

            for (int i = 5; i >= 1; i--)
            {
                gs2.Add(i);
            }
            Console.WriteLine("set2: {0}", gs2);
            Assert.That(gs1.Equals(gs2), Is.True);
            gs2.Add(10);
            Assert.That(gs1.Equals(gs2), Is.False);
        }
示例#8
0
        public void TestUnion_EmptySet()
        {
            GenericSet <int> gs1 = new GenericSet <int>();

            for (int i = 1; i <= 8; i++)
            {
                gs1.Add(i);
            }
            Console.WriteLine(gs1);

            GenericSet <int> gs2 = new GenericSet <int>();

            Assert.That(gs2.IsEmpty, Is.True);
            Console.WriteLine(gs2);

            GenericSet <int> union = gs1.Union(gs2);

            Assert.That(union.Size, Is.EqualTo(gs1.Size));
            Assert.That(union.Contains(15), Is.False);
            Assert.That(union.Contains(1), Is.True);
        }
示例#9
0
 public void AddTest()
 {
     set.Add(1);
     Assert.AreEqual(1, set.Count);
 }