static void Main(string[] args) { //Usage sample Collections.LinkedList<int> list = new Collections.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)); /// ... }
public void testSize() { list = new Collections.LinkedList<int>(); //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()); } }
public void genericListTest() { Collections.LinkedList<int> intsList = new Collections.LinkedList<int>();// -> INT TYPE WAS TESTED Collections.LinkedList<double> doublesList = new Collections.LinkedList<double>(); Collections.LinkedList<String> strsList = new Collections.LinkedList<String>(); Collections.LinkedList<Persona> personsList = new Collections.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)); }
public void TestRemove() { list = new Collections.LinkedList<int>(); 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)); }