Esempio n. 1
0
        public void Remove()
        {
            SimpleList <string> strings = new SimpleList <string>(4);

            strings.Add("A");
            strings.Add("B");
            strings.Add("C");
            strings.Add("D");

            strings.Remove("A");
            Assert.AreEqual("B", strings[0]);
            Assert.AreEqual("C", strings[1]);
            Assert.AreEqual("D", strings[2]);

            strings = new SimpleList <string>(4);
            strings.Add("A");
            strings.Add("B");
            strings.Add("C");
            strings.Add("D");

            strings.Remove("B");
            Assert.AreEqual("A", strings[0]);
            Assert.AreEqual("C", strings[1]);
            Assert.AreEqual("D", strings[2]);

            strings = new SimpleList <string>(4);
            strings.Add("A");
            strings.Add("B");
            strings.Add("C");
            strings.Add("D");

            strings.Remove("C");
            Assert.AreEqual("A", strings[0]);
            Assert.AreEqual("B", strings[1]);
            Assert.AreEqual("D", strings[2]);

            strings = new SimpleList <string>(4);
            strings.Add("A");
            strings.Add("B");
            strings.Add("C");
            strings.Add("D");

            strings.Remove("D");
            Assert.AreEqual("A", strings[0]);
            Assert.AreEqual("B", strings[1]);
            Assert.AreEqual("C", strings[2]);

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => { strings.Remove("W"); });

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => { strings.Remove("Y"); });
        }
Esempio n. 2
0
        public void CanAddAndRemove()
        {
            var sourceNode = new Node(Utils.Id("foo"));
            var simpleList = new SimpleList <I32>();

            simpleList.Init(sourceNode, db);
            for (int i = 0; i < 100; i++)
            {
                simpleList.Add(new I32 {
                    v = i
                });
            }
            for (int i = 0; i < 100; i += 2)
            {
                simpleList.Remove(new I32 {
                    v = i
                });
            }
            for (int i = 0; i < 100; i++)
            {
                if (i % 2 == 1)
                {
                    Assert.Contains(new I32 {
                        v = i
                    }, simpleList);
                }
                else
                {
                    Assert.DoesNotContain(new I32 {
                        v = i
                    }, simpleList);
                }
            }
        }
Esempio n. 3
0
 public void RemoveObjectFromList()
 {
     var list = new SimpleList<int>() { 1, 2, 3, 4, 5, 6, 7, 8 };
     var newList = new SimpleList<int>() { 1, 2, 4, 5, 6, 7, 8 };
     list.Remove(3);
     CollectionAssert.Equals(newList, list);
 }
Esempio n. 4
0
    static void Main()
    {
        SimpleList test = new SimpleList();

        // Populate the List
        Console.WriteLine("Populate the List");
        test.Add("one");
        test.Add("two");
        test.Add("three");
        test.Add("four");
        test.Add("five");
        test.Add("six");
        test.Add("seven");
        test.Add("eight");
        test.PrintContents();
        Console.WriteLine();

        // Remove elements from the list
        Console.WriteLine("Remove elements from the list");
        test.Remove("six");
        test.Remove("eight");
        test.PrintContents();
        Console.WriteLine();

        // Add an element to the end of the list
        Console.WriteLine("Add an element to the end of the list");
        test.Add("nine");
        test.PrintContents();
        Console.WriteLine();

        // Insert an element into the middle of the list
        Console.WriteLine("Insert an element into the middle of the list");
        test.Insert(4, "number");
        test.PrintContents();
        Console.WriteLine();

        // Check for specific elements in the list
        Console.WriteLine("Check for specific elements in the list");
        Console.WriteLine("List contains \"three\": {0}", test.Contains("three"));
        Console.WriteLine("List contains \"ten\": {0}", test.Contains("ten"));
    }