Beispiel #1
0
        public void Simple()
        {
            var pascalSet = new PascalSet(0, 500);
            Assert.IsFalse(pascalSet.IsReadOnly);

            pascalSet.Add(50);
            Assert.IsFalse(pascalSet.IsReadOnly);

            pascalSet.Add(100);
            Assert.IsFalse(pascalSet.IsReadOnly);
        }
Beispiel #2
0
        public void TestIsReadOnly()
        {
            PascalSet s = new PascalSet(0, 500);

            Assert.AreEqual(s.IsReadOnly, false);

            s.Add(50);
            Assert.AreEqual(s.IsReadOnly, false);

            s.Add(100);
            Assert.AreEqual(s.IsReadOnly, false);
        }
Beispiel #3
0
        public void Simple()
        {
            var pascalSet = new PascalSet(0, 500);

            Assert.IsFalse(pascalSet.IsReadOnly);

            pascalSet.Add(50);
            Assert.IsFalse(pascalSet.IsReadOnly);

            pascalSet.Add(100);
            Assert.IsFalse(pascalSet.IsReadOnly);
        }
Beispiel #4
0
        public void TestIsFull()
        {
            PascalSet s = new PascalSet(0, 500);

            Assert.AreEqual(s.IsFull, false);

            s.Add(50);
            Assert.AreEqual(s.IsFull, false);

            s.Add(100);
            Assert.AreEqual(s.IsFull, false);
        }
Beispiel #5
0
        public void Simple()
        {
            var pascalSet = new PascalSet(0, 500);
            Assert.IsTrue(pascalSet.IsEmpty);

            pascalSet.Add(50);
            Assert.IsFalse(pascalSet.IsEmpty);

            pascalSet.Add(100);
            Assert.IsFalse(pascalSet.IsEmpty);

            pascalSet.Clear();
            Assert.IsTrue(pascalSet.IsEmpty);
        }
Beispiel #6
0
        public void Simple()
        {
            var pascalSet = new PascalSet(0, 500);

            Assert.IsTrue(pascalSet.IsEmpty);

            pascalSet.Add(50);
            Assert.IsFalse(pascalSet.IsEmpty);

            pascalSet.Add(100);
            Assert.IsFalse(pascalSet.IsEmpty);

            pascalSet.Clear();
            Assert.IsTrue(pascalSet.IsEmpty);
        }
Beispiel #7
0
        public void TestIsEmpty()
        {
            PascalSet s = new PascalSet(0, 500);

            Assert.AreEqual(s.IsEmpty, true);

            s.Add(50);
            Assert.AreEqual(s.IsEmpty, false);

            s.Add(100);
            Assert.AreEqual(s.IsEmpty, false);

            s.Clear();
            Assert.AreEqual(s.IsEmpty, true);
        }
Beispiel #8
0
        public void IntersectionExample()
        {
            // Create a sample PascalSet
            var pascalSet1 = new PascalSet(100);

            // Set a couple of values in the PascalSet
            for (var i = 0; i < 100; i += 10)
            {
                pascalSet1.Add(i);
            }

            // Create another sample PascalSet
            var pascalSet2 = new PascalSet(100)
            {
                4, 6, 7, 10, 30
            };

            // Get the intersection of the two sets
            var intersection = pascalSet1.Intersection(pascalSet2);

            // The intersection will contain values that was
            // contained in both sets.
            Assert.IsTrue(intersection[10]);
            Assert.IsTrue(intersection[30]);
            Assert.AreEqual(intersection.Count, 2);
        }
Beispiel #9
0
        public void RemoveExample()
        {
            // Create a sample PascalSet, with a lower bound
            // of 1, and an upper bound of 100
            var pascalSet = new PascalSet(0, 100);

            // Add a couple items to the set
            for (var i = 0; i < 100; i += 10)
            {
                pascalSet.Add(i);
            }

            // There should be 10 items in the set
            Assert.AreEqual(pascalSet.Count, 10);

            // Remove 30 from the set
            var success = pascalSet.Remove(30);

            // The item would have been removed
            Assert.IsTrue(success);

            // There should be 9 items in the set now
            Assert.AreEqual(pascalSet.Count, 9);

            // Try and remove an item not in the set
            success = pascalSet.Remove(15);

            // Which, of course, wouldn't be successful
            Assert.IsFalse(success);
        }
Beispiel #10
0
        public void InverseExample()
        {
            // Create a sample PascalSet
            var pascalSet = new PascalSet(100);

            // Set a couple of values in the PascalSet
            for (var i = 0; i < 100; i += 10)
            {
                pascalSet.Add(i);
            }

            // Get the inverse of the set
            var inverse = pascalSet.Inverse();

            // All the items that were not included in the original
            // set will be in the inverse.
            for (var i = 0; i < 100; i++)
            {
                if ((i % 10) > 0)
                {
                    Assert.IsTrue(inverse[i]);
                }
            }

            // We'll have 91 items in the set (101 - 10)
            Assert.AreEqual(inverse.Count, 91);
        }
Beispiel #11
0
        public void AddExample()
        {
            // Create a sample PascalSet instance
            var pascalSet = new PascalSet(100);

            // Add the 10th item to the set
            pascalSet.Add(10);

            // Add the 57th item to the set
            pascalSet.Add(57);

            // There will be two items in the set
            Assert.AreEqual(pascalSet.Count, 2);

            // And the set will contain the 10th and 57th item
            Assert.IsTrue(pascalSet.Contains(10));
            Assert.IsTrue(pascalSet.Contains(57));
        }
Beispiel #12
0
        public void ClearExample()
        {
            // Create a sample PascalSet instance
            var pascalSet = new PascalSet(100);

            // Add the 10th item to the set
            pascalSet.Add(10);

            // Add the 57th item to the set
            pascalSet.Add(57);

            // There will be two items in the set
            Assert.AreEqual(pascalSet.Count, 2);

            // Remove all items from the set
            pascalSet.Clear();

            // There will be no items left in the set
            Assert.AreEqual(pascalSet.Count, 0);
        }
Beispiel #13
0
        public void CountExample()
        {
            // Create a sample PascalSet instance
            var pascalSet = new PascalSet(100);

            // Add the 10th item to the set
            pascalSet.Add(10);

            // There will be one item in the set
            Assert.AreEqual(pascalSet.Count, 1);

            // Add the 57th item to the set
            pascalSet.Add(57);

            // There will be two items in the set
            Assert.AreEqual(pascalSet.Count, 2);

            // Clear the set, thereby removing all items
            pascalSet.Clear();

            // There will be no items left in the set
            Assert.AreEqual(pascalSet.Count, 0);
        }
Beispiel #14
0
        public void CopyToExample()
        {
            // Create a sample PascalSet instance
            var pascalSet = new PascalSet(100);

            // Set a couple of values in the PascalSet
            for (var i = 0; i < 100; i += 10)
            {
                pascalSet.Add(i);
            }

            // Create an array to store the items in
            var values = new int[10];

            // Copy the items in the set to the array, at index 0
            pascalSet.CopyTo(values, 0);
        }
Beispiel #15
0
        public void GetEnumeratorExample()
        {
            var pascalSet = new PascalSet(100);

            // Set a couple of values in the PascalSet
            for (var i = 0; i < 100; i += 10)
            {
                pascalSet.Add(i);
            }

            // Enumerate over the items in the PascalSet,
            // printing them to the standard console
            using (var enumerator = pascalSet.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Console.WriteLine(enumerator.Current);
                }
            }
        }
Beispiel #16
0
        public void IsFullExample()
        {
            // Create a sample PascalSet with a capacity of
            // 100 items (1 - 100)
            var pascalSet = new PascalSet(1, 100);

            // The set is initially empty
            Assert.IsFalse(pascalSet.IsFull);

            // The IsFull Property only returns true when every
            // possible item in the set's universe has been added
            // to the set.  We add some items to illustrate.
            for (var i = 1; i <= 100; i++)
            {
                pascalSet.Add(i);
            }

            // The set contains 100 items - thus, it's full
            Assert.AreEqual(pascalSet.Count, 100);
            Assert.IsTrue(pascalSet.IsFull);
        }
Beispiel #17
0
        public void IsEmptyExample()
        {
            // Create a sample PascalSet
            var pascalSet = new PascalSet(100);

            // The PascalSet will initially be empty
            Assert.IsTrue(pascalSet.IsEmpty);

            // Add a couple of values in the PascalSet
            for (var i = 0; i < 100; i += 10)
            {
                pascalSet.Add(i);
            }

            // Not empty anymore...
            Assert.IsFalse(pascalSet.IsEmpty);

            // Clear the PascalSet, making it empty once more.
            pascalSet.Clear();
            Assert.IsTrue(pascalSet.IsEmpty);
        }
Beispiel #18
0
        public void AcceptExample()
        {
            // Create a sample PascalSet instance
            var set = new PascalSet(100);

            // Set a couple of values in the PascalSet
            for (var i = 0; i < 100; i += 10)
            {
                set.Add(i);
            }

            // Create a counting visitor that will count the number of
            // items visited.
            var visitor = new CountingVisitor <int>();

            // Open up the door for the visitor
            set.AcceptVisitor(visitor);

            // The visitor will have visited 10 items
            Assert.AreEqual(visitor.Count, 10);
        }
Beispiel #19
0
        public void Simple()
        {
            var pascalSet = new PascalSet(0, 100);
            Assert.IsFalse(pascalSet.IsFull);

            for (var i = 0; i <= 100; i++)
            {
                pascalSet.Add(i);

                if (i < 100)
                {
                    Assert.IsFalse(pascalSet.IsFull);
                }
                else
                {
                    Assert.IsTrue(pascalSet.IsFull);
                }
            }

            pascalSet.Clear();

            Assert.IsFalse(pascalSet.IsFull);
        }
Beispiel #20
0
        public void Simple()
        {
            var pascalSet = new PascalSet(0, 100);

            Assert.IsFalse(pascalSet.IsFull);

            for (var i = 0; i <= 100; i++)
            {
                pascalSet.Add(i);

                if (i < 100)
                {
                    Assert.IsFalse(pascalSet.IsFull);
                }
                else
                {
                    Assert.IsTrue(pascalSet.IsFull);
                }
            }

            pascalSet.Clear();

            Assert.IsFalse(pascalSet.IsFull);
        }