예제 #1
0
        public void TestGet()
        {
            list = new Colletions.LinkedList();
            for(int i=0; i<50; i++){
                list.add(i);
                Assert.AreEqual(i+1, list.size());
            }

            list.add(2, 999);
            Assert.AreEqual(999, list.get(2));
            Assert.AreEqual(2, list.get(3));
            Assert.AreEqual(1, list.get(1));

            list = new Colletions.LinkedList();
            for (int i = 0; i < 50; i++)
            {
                list.add(i);
                Assert.AreEqual(i + 1, list.size());
            }

            list.add(0,999);
            Assert.AreEqual(999, list.get(0));
            //System.Console.WriteLine(list.size());
            list.add(list.size()-1, 888);
            Assert.AreEqual(49, list.get(list.size() - 3));
            Assert.AreEqual(888, list.get(list.size()-2));
        }
예제 #2
0
        public void genericListTest()
        {
            Colletions.LinkedList<int> intsList = new Colletions.LinkedList<int>();// -> INT TYPE WAS TESTED
            Colletions.LinkedList<double> doublesList = new Colletions.LinkedList<double>();
            Colletions.LinkedList<String> strsList = new Colletions.LinkedList<String>();
            Colletions.LinkedList<Persona> personsList = new Colletions.LinkedList<Persona>();

            //GENERAL TEST FOR DOUBLES
            for (int i=0; i<50; i++) {
                doublesList.add((double) i); //add double
                strsList.add(i.ToString()); //add string
                Persona auxP = new Persona(i.ToString());
                personsList.add(auxP); // add persons

                Assert.AreEqual((double) i, doublesList.get(i));//get double
                Assert.AreEqual(i.ToString(), strsList.get(i));//get string
                Assert.AreEqual(auxP, personsList.get(i)); //get person

                Assert.AreEqual(i, doublesList.indexOf((double) i));//index of a double
                Assert.AreEqual(i, strsList.indexOf(i.ToString()));//index of a string
                Assert.AreEqual(i, personsList.indexOf(auxP));// index of a person

                Assert.AreEqual(true, doublesList.contains((double) i));//contains double?
                Assert.AreEqual(true, strsList.contains(i.ToString()));//contains string?
                Assert.AreEqual(true, personsList.contains(auxP));//contains person?
            }
            Assert.AreEqual(50, doublesList.size());
            Assert.AreEqual(50, strsList.size());
            Assert.AreEqual(50, personsList.size());

            //removing doubles
            for (int i=0; i<50; i++) {
                Persona auxP = new Persona(i.ToString());
                Assert.AreEqual((double) i, doublesList.remove((double) i));
                Assert.AreEqual(i.ToString(), strsList.remove(i.ToString()));
                Assert.AreEqual(auxP, personsList.remove(auxP));
            }
            Assert.AreEqual(0, doublesList.size());
            Assert.AreEqual(0, strsList.size());
            Assert.AreEqual(0, personsList.size());

            //removing by position
            Persona p1 = new Persona("dni1");
            Persona p2 = new Persona("dni2");

            doublesList.add(1.0);
            doublesList.add(2.0);
            strsList.add("texto1");
            strsList.add("texto2");
            personsList.add(p1);
            personsList.add(p2);

            Assert.AreEqual(1.0, doublesList.removeByIndex(0));
            Assert.AreEqual(2.0, doublesList.removeByIndex(0));
            Assert.AreEqual("texto1", strsList.removeByIndex(0));
            Assert.AreEqual("texto2", strsList.removeByIndex(0));
            Assert.AreEqual(p1, personsList.removeByIndex(0));
            Assert.AreEqual(p2, personsList.removeByIndex(0));
        }
예제 #3
0
 public void testAllIndexesOf()
 {
     list = new Colletions.LinkedList();
     for (int i=0; i<10; i++) {
         list.add(1);
     }
     int[] expected = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     Assert.AreEqual(expected.Length, list.size());
     CollectionAssert.AreEqual(expected, list.allIndexesOf(1));
 }
예제 #4
0
        public void TestAdd()
        {
            list = new Colletions.LinkedList();

            //Positive tests
            //Adding objects:
            //Adding Integers or ints
            list.add(1);
            Assert.AreEqual(1, list.size());
            //Adding Strings and Chars
            list.add("a");
            Assert.AreEqual(2, list.size());
        }
예제 #5
0
        static void Main(string[] args)
        {
            //Usage sample
            Colletions.LinkedList<int> list = new Colletions.LinkedList<int>();

            //ADDING OPERATIONS
            list.add(1);
            list.add(2);
            list.add(3);
            list.add(3);
            list.add(4);
            list.add(5);
            list.add(6);
            list.add(6);
            list.add(6);
            list.add(6);

            list.add(1, 1); // adding by index
            Console.WriteLine(list.ToString());

            //REMOVE
            list.remove(1);
            list.remove(2);
            list.removeByIndex(4); //removing by index
            list.removeAllValues(6); //removing all '6' in the linkedlist
            Console.WriteLine(list.ToString());

            //INDEXOF
            Console.WriteLine("El 3 se encuentra en la posición {0}", list.indexOf(3));
            int[] indexes = list.allIndexesOf(3);
            String positions = "[ ";
            for (int i=0; i<indexes.Length; i++) {
                if (i != indexes.Length - 1)
                    positions += indexes[i] + ", ";
                else
                    positions += indexes[i] + " ]";
            }
            Console.WriteLine("Estas son todas las posiciones en las que hay un 3: {0}", positions);

            //SIZE
            Console.WriteLine("El tamaño de la lista actualmente es: {0}", list.size());

            //GET/SET
            Console.WriteLine("El primer elemento de la lista es el: {0}", list.get(0));
            list.set(0, 10);
            Console.WriteLine("Ahora el primer elemento a cambiado (tras usar el setter)");
            Console.WriteLine("El primer elemento de la lista es el: {0}", list.get(0));

            /// ...
        }
예제 #6
0
        public void TestAddByPosition()
        {
            list = new Colletions.LinkedList();
            for (int i = 0; i < 50; i++)
            {
                list.add(i);
                Assert.AreEqual(i + 1, list.size());
            }

            //Positive tests
            //Implemented inside TestGet() for testing both methods

            //Negative tests
            //index>=size
            list.add(list.size(), 999);
            list.add(list.size()+1, 999);
            Assert.AreEqual(50, list.size());

            //index<0
            list.add(-6, 999);
            Assert.AreEqual(50, list.size());
        }
예제 #7
0
        public void testSize()
        {
            list = new Colletions.LinkedList();

            //list.add(1);
            //Assert.AreEqual(1, list.size());

            //adding elems
            for (int i=1; i<51; i++) {
                list.add(i);
                Assert.AreEqual(i, list.size());
            }

            //removing elems
            for (int i = 1; i < 51; i++){
                list.remove(i);
                Assert.AreEqual(50-i, list.size());
            }
        }
예제 #8
0
        public void testRemoveByIndex()
        {
            list = new Colletions.LinkedList();
            Colletions.LinkedList list2 = new Colletions.LinkedList();
            Colletions.LinkedList list3 = new Colletions.LinkedList();

            for (int i = 0; i < 50; i++)
            {
                list.add(i);
                list2.add(i);
                list3.add(i);
            }

            //remove first element
            list.removeByIndex(0);
            Assert.AreEqual(1, list.get(0));
            Assert.AreEqual(49, list.size());

            //remove last element
            list.removeByIndex(list.size()-1);
            Assert.AreEqual(48, list.get(list.size() - 1));
            Assert.AreEqual(48, list.size());

            //remove [firstElement, lastElement]
            Assert.AreEqual(0, list2.removeByIndex(0));
            Assert.AreEqual(25+1, list2.removeByIndex(25));
            Assert.AreEqual(32+2, list2.removeByIndex(32));
            //Assert.AreEqual(49, list2.removeByIndex(list2.size()-1));

            //remove all
            for (int i = 0; i < 50; i++)
            {
                list3.removeByIndex(0);
            }
            Assert.AreEqual(0, list3.size());

            //Negative tests
            //Index >= size

            //Index < 0
        }
예제 #9
0
        public void testRemoveAllValues()
        {
            list = new Colletions.LinkedList();
            for (int i = 0; i < 10; i++)
            {
                list.add(1);
            }
            list.add(2);
            list.add(3);
            int auxSize = list.size();

            object[] expected = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
            object[] result = list.removeAllValues(1);
            CollectionAssert.AreEqual(expected, result);
            Assert.AreEqual(expected.Length, result.Length);
            Assert.AreEqual(auxSize-result.Length, list.size());
        }
예제 #10
0
        public void TestRemove()
        {
            list = new Colletions.LinkedList();
            list.add(1);
            list.add(2);
            list.add(3);
            list.add(1);
            list.add(3);

            // 1, 2, 3, 1, 3, remove(3) -> 1,2,1,3
            Assert.AreEqual(3, list.remove(3));
            Assert.AreEqual(4, list.size());
            Assert.AreEqual(1, list.get(0));
            Assert.AreEqual(2, list.get(1));
            Assert.AreEqual(1, list.get(2));
            Assert.AreEqual(3, list.get(3));
        }
예제 #11
0
 public void testIndexOf()
 {
     list = new Colletions.LinkedList();
     for (int i=0; i<50; i++) {
         list.add(i);
         Assert.AreEqual(i, list.indexOf(i));
     }
 }
예제 #12
0
        public void testContains()
        {
            list = new Colletions.LinkedList<int>();
            for (int i=0; i<50; i++) {
                list.add(i);
                Assert.AreEqual(true, list.contains(i));
            }

            Assert.AreEqual(false, list.contains(50));
            Assert.AreEqual(false, list.contains(51));
            // ...
        }