public void Clear_BeforeLooping()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(3);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };

            list.Add(one);
            list.Add(two);

            list.Clear();

            Assert.IsEmpty(list, "List should be empty as it has just been cleared");
            Assert.AreEqual(-1, list.CurrentIndex, "The index should have been reset by the clear");
        }
        public void Contains_AboutToLoop()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(2);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };
            SimpleElement three = new SimpleElement() { String = "Three" };

            list.Add(one);
            list.Add(two);

            Assert.IsTrue(list.Contains(two), "The element should be in the list");
            Assert.IsTrue(list.Contains(one), "The element should be in the list");
            Assert.IsFalse(list.Contains(three), "The element should not be in the list");
        }
        public void IndexOf_BeforeLooping()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(3);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };
            SimpleElement three = new SimpleElement() { String = "Three" };

            list.Add(one);
            list.Add(two);

            Assert.AreEqual(1, list.IndexOf(two), "Index should be 1 as this is the second element");
            Assert.AreEqual(0, list.IndexOf(one), "Index should be 0 as this is the first element");
            Assert.AreEqual(-1, list.IndexOf(three), "Index should be -1 as the item is not in the list");
        }
        public void Enumerator_BeforeLooping()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(3);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };

            list.Add(one);
            list.Add(two);

            List<SimpleElement> actual = new List<SimpleElement>();
            foreach (SimpleElement cur in list)
            {
                actual.Add(cur);
            }

            Assert.AreEqual(2, actual.Count, "The foreach should have yielded 2 items");
            Assert.AreEqual(one, actual[0], "First yielded item is wrong");
            Assert.AreEqual(two, actual[1], "Second yielded item is wrong");
        }
        public void IndexOf_AfterLooping()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(2);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };
            SimpleElement three = new SimpleElement() { String = "Three" };

            list.Add(one);
            list.Add(two);
            list.Add(three);

            Assert.AreEqual(1, list.IndexOf(two), "Index should be 1 as this is the second element");
            Assert.AreEqual(-1, list.IndexOf(one), "Index should be -1 as this item has been replaced by new content");
            Assert.AreEqual(0, list.IndexOf(three), "Index should be 0 as the item is the first to be added after looping");
        }
        public void Enumerator_AfterLooping_LongerList()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(3);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };
            SimpleElement three = new SimpleElement() { String = "Three" };
            SimpleElement four = new SimpleElement() { String = "Four" };
            SimpleElement five = new SimpleElement() { String = "Five" };

            list.Add(one); // ==> 0
            list.Add(two); // ==> 1
            list.Add(three); // ==> 2
            list.Add(four); // ==> 0
            list.Add(five); // ==> 1

            List<SimpleElement> actual = new List<SimpleElement>();
            foreach (SimpleElement cur in list)
            {
                actual.Add(cur);
            }

            Assert.AreEqual(3, actual.Count, "The foreach should have yielded 3 items");
            Assert.AreEqual(three, actual[0], "First yielded item is wrong");
            Assert.AreEqual(four, actual[1], "Second yielded item is wrong");
            Assert.AreEqual(five, actual[2], "Third yielded item is wrong");
        }
        public void Enumerator_AboutToLoop_LongerList()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(5);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };
            SimpleElement three = new SimpleElement() { String = "Three" };
            SimpleElement four = new SimpleElement() { String = "Four" };
            SimpleElement five = new SimpleElement() { String = "FIve" };

            list.Add(one);
            list.Add(two);
            list.Add(three);
            list.Add(four);
            list.Add(five);

            List<SimpleElement> actual = new List<SimpleElement>();
            foreach (SimpleElement cur in list)
            {
                actual.Add(cur);
            }

            Assert.AreEqual(5, actual.Count, "The foreach should have yielded 5 items");
            Assert.AreEqual(one, actual[0], "First yielded item is wrong");
            Assert.AreEqual(two, actual[1], "Second yielded item is wrong");
            Assert.AreEqual(three, actual[2], "Third yielded item is wrong");
            Assert.AreEqual(four, actual[3], "Fourth yielded item is wrong");
            Assert.AreEqual(five, actual[4], "Fifth yielded item is wrong");
        }
        public void Count_BeforeLooping()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(3);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };

            list.Add(one);
            list.Add(two);

            Assert.AreEqual(2, list.Count);
        }
        public void CopyTo_BeforeLooping_IndexGreaterThanZero()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(3);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };

            list.Add(one);
            list.Add(two);

            SimpleElement[] array = new SimpleElement[3];

            list.CopyTo(array, 1);

            Assert.AreEqual(default(SimpleElement), array[0]);
            Assert.AreEqual(one, array[1]);
        }
Esempio n. 10
0
        public void CopyTo_AfterLooping_FromIndexZero()
        {
            CircularList<SimpleElement> list = new CircularList<SimpleElement>(2);

            SimpleElement one = new SimpleElement() { String = "One" };
            SimpleElement two = new SimpleElement() { String = "Two" };
            SimpleElement three = new SimpleElement() { String = "Three" };

            list.Add(one);
            list.Add(two);
            list.Add(three);

            SimpleElement[] array = new SimpleElement[2];

            list.CopyTo(array, 0);

            Assert.AreEqual(two, array[0]);
            Assert.AreEqual(three, array[1]);
        }