Created
August 22, 2016 21:01
-
-
Save manoelf/8d4a2752274006d9d5532ce7910823ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class BritoTeste extends StudentLinkedListTest{ | |
private DoubleLinkedList<Integer> lista1; | |
private DoubleLinkedList<Integer> lista2; | |
private DoubleLinkedList<Integer> lista3; | |
private DoubleLinkedList<Integer> lista4; | |
@Before | |
public void setUp() throws Exception { | |
super.setUp(); | |
getImplementations(); | |
// Lista com 3 elementos. | |
lista1.insert(3); | |
lista1.insert(2); | |
lista1.insert(1); | |
// Lista com 5 elementos | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insert(1); | |
Assert.assertTrue(lista3.size() == 1); | |
lista3.insert(1); | |
Assert.assertTrue(lista3.size() == 2); | |
lista3.insert(1); | |
Assert.assertTrue(lista3.size() == 3); | |
lista3.insert(1); | |
Assert.assertTrue(lista3.size() == 4); | |
lista3.insert(1); | |
Assert.assertTrue(lista3.size() == 5); | |
lista4.insert(5); | |
lista4.insert(4); | |
lista4.insert(3); | |
lista4.insert(2); | |
lista4.insert(1); | |
} | |
private void getImplementations(){ | |
//TODO O aluno deve ajustar aqui para instanciar sua implementação | |
lista1 = new DoubleLinkedListImpl<>(); | |
lista2 = new DoubleLinkedListImpl<>(); | |
lista3 = new DoubleLinkedListImpl<>(); | |
lista4 = new DoubleLinkedListImpl<>(); | |
} | |
@Test | |
public void testIsEmpty() { | |
Assert.assertFalse(lista1.isEmpty()); | |
Assert.assertTrue(lista2.isEmpty()); | |
Assert.assertFalse(lista3.isEmpty()); | |
Assert.assertFalse(lista4.isEmpty()); | |
} | |
@Test | |
public void testSize() { | |
Assert.assertEquals(3, lista1.size()); | |
Assert.assertEquals(0, lista2.size()); | |
Assert.assertEquals(5, lista3.size()); | |
Assert.assertEquals(5, lista3.size()); | |
} | |
@Test | |
public void testSearch() { | |
Assert.assertTrue(2 == lista1.search(2)); | |
Assert.assertNull(lista1.search(4)); | |
Assert.assertFalse(3 == lista1.search(2)); | |
Assert.assertTrue(2 == lista4.search(2)); | |
Assert.assertTrue(3 == lista4.search(3)); | |
Assert.assertNull(lista4.search(6)); | |
Assert.assertTrue(4 == lista4.search(4)); | |
Assert.assertNull(lista4.search(0)); | |
Assert.assertTrue(5 == lista4.search(5)); | |
Assert.assertTrue(1 == lista4.search(1)); | |
} | |
@Test | |
public void testInsert() { | |
Assert.assertEquals(3, lista1.size()); | |
lista1.insert(5); | |
lista1.insert(7); | |
Assert.assertEquals(5, lista1.size()); | |
Assert.assertEquals(0, lista2.size()); | |
lista2.insert(4); | |
lista2.insert(7); | |
Assert.assertEquals(2, lista2.size()); | |
} | |
@Test | |
public void testRemove() { | |
Assert.assertTrue(lista3.size() == 5); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.size() == 4); | |
lista3.remove(100); | |
lista3.remove(500); | |
Assert.assertTrue(lista3.size() == 4); | |
lista3.remove(1); | |
lista3.remove(329); | |
lista3.remove(32989); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.size() == 2); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.size() == 1); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.size() == 0); | |
Assert.assertTrue(lista3.isEmpty()); | |
Assert.assertTrue(lista4.size() == 5); | |
Assert.assertTrue(1 == lista4.search(1)); | |
lista4.remove(1); | |
Assert.assertNull(lista4.search(1)); | |
Assert.assertTrue(lista4.size() == 4); | |
Assert.assertTrue(lista4.size() == 4); | |
Assert.assertTrue(5 == lista4.search(5)); | |
lista4.remove(5); | |
Assert.assertNull(lista4.search(5)); | |
Assert.assertTrue(lista4.size() == 3); | |
Assert.assertTrue(lista4.size() == 3); | |
Assert.assertTrue(3 == lista4.search(3)); | |
lista4.remove(3); | |
Assert.assertNull(lista4.search(3)); | |
Assert.assertTrue(lista4.size() == 2); | |
Assert.assertTrue(lista4.size() == 2); | |
Assert.assertTrue(2 == lista4.search(2)); | |
lista4.remove(2); | |
Assert.assertNull(lista4.search(2)); | |
Assert.assertTrue(lista4.size() == 1); | |
Assert.assertTrue(lista4.size() == 1); | |
Assert.assertTrue(4 == lista4.search(4)); | |
lista4.remove(4); | |
Assert.assertNull(lista4.search(4)); | |
Assert.assertTrue(lista4.size() == 0); | |
Assert.assertTrue(lista4.isEmpty()); | |
Assert.assertEquals(3, lista1.size()); | |
lista1.remove(2); | |
lista1.remove(1); | |
Assert.assertEquals(1, lista1.size()); | |
lista1.remove(4); | |
lista1.remove(20); | |
lista1.remove(10); | |
Assert.assertEquals(1, lista1.size()); | |
} | |
@Test | |
public void testToArray() { | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
Assert.assertArrayEquals(new Integer[] { 3, 2, 1 }, lista1.toArray()); | |
Assert.assertArrayEquals(new Integer[]{ 1, 1, 1, 1, 1}, lista3.toArray()); | |
Assert.assertArrayEquals(new Integer[]{ 5, 4, 3, 2, 1}, lista4.toArray()); | |
} | |
// Métodos de DoubleLinkedList | |
@Test | |
public void testInsertFirst(){ | |
lista1.insertFirst(4); | |
Assert.assertArrayEquals(new Integer[] { 4, 3, 2, 1 }, lista1.toArray()); | |
lista1.insertFirst(5); | |
Assert.assertArrayEquals(new Integer[] { 5, 4, 3, 2, 1 }, lista1.toArray()); | |
lista1.insertFirst(6); | |
Assert.assertArrayEquals(new Integer[] { 6, 5, 4, 3, 2, 1 }, lista1.toArray()); | |
} | |
@Test | |
public void testRemoveFirst(){ | |
lista1.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 2, 1 }, lista1.toArray()); | |
lista1.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 1 }, lista1.toArray()); | |
lista1.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { }, lista1.toArray()); | |
lista1.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { }, lista1.toArray()); | |
} | |
@Test | |
public void testRemoveLast(){ | |
lista1.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 3, 2 }, lista1.toArray()); | |
lista1.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 3 }, lista1.toArray()); | |
lista1.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { }, lista1.toArray()); | |
lista1.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { }, lista1.toArray()); | |
} | |
@Test | |
public void removeTest() { | |
lista2.insert(0); | |
lista2.insert(1); | |
lista2.insert(2); | |
lista2.insert(3); | |
lista2.insert(4); | |
Assert.assertArrayEquals(new Integer[] { 0, 1, 2, 3, 4 }, lista2.toArray()); | |
lista2.remove(0); | |
Assert.assertArrayEquals(new Integer[] { 1, 2, 3, 4 }, lista2.toArray()); | |
lista2.remove(1); | |
Assert.assertArrayEquals(new Integer[] { 2, 3, 4 }, lista2.toArray()); | |
lista2.remove(2); | |
Assert.assertArrayEquals(new Integer[] { 3, 4 }, lista2.toArray()); | |
lista2.remove(3); | |
Assert.assertArrayEquals(new Integer[] { 4 }, lista2.toArray()); | |
lista2.remove(4); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
lista2.insertFirst(4); | |
lista2.insertFirst(3); | |
lista2.insertFirst(2); | |
lista2.insertFirst(1); | |
lista2.insertFirst(0); | |
Assert.assertArrayEquals(new Integer[] { 0, 1, 2, 3, 4 }, lista2.toArray()); | |
lista2.remove(0); | |
Assert.assertArrayEquals(new Integer[] { 1, 2, 3, 4 }, lista2.toArray()); | |
lista2.remove(1); | |
Assert.assertArrayEquals(new Integer[] { 2, 3, 4 }, lista2.toArray()); | |
lista2.remove(2); | |
Assert.assertArrayEquals(new Integer[] { 3, 4 }, lista2.toArray()); | |
lista2.remove(3); | |
Assert.assertArrayEquals(new Integer[] { 4 }, lista2.toArray()); | |
lista2.remove(4); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
lista2.insertFirst(0); | |
lista2.insertFirst(1); | |
lista2.insertFirst(2); | |
lista2.insertFirst(3); | |
lista2.insertFirst(4); | |
Assert.assertArrayEquals(new Integer[] { 4, 3, 2, 1, 0 }, lista2.toArray()); | |
lista2.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 4, 3, 2, 1,}, lista2.toArray()); | |
lista2.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 4, 3, 2, }, lista2.toArray()); | |
lista2.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 4, 3 }, lista2.toArray()); | |
lista2.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 4 }, lista2.toArray()); | |
lista2.removeLast(); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
lista2.insertFirst(0); | |
lista2.insertFirst(1); | |
lista2.insertFirst(2); | |
lista2.insertFirst(3); | |
lista2.insertFirst(4); | |
Assert.assertArrayEquals(new Integer[] { 4, 3, 2, 1, 0 }, lista2.toArray()); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 3, 2, 1, 0 }, lista2.toArray()); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 2, 1, 0 }, lista2.toArray()); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 1, 0 }, lista2.toArray()); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 0 }, lista2.toArray()); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
lista2.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import adt.queue.QueueDoubleLinkedListImpl; | |
import adt.queue.QueueOverflowException; | |
import adt.queue.QueueUnderflowException; | |
public class ItaloTesteQueue { | |
public QueueDoubleLinkedListImpl<Integer> queue1; | |
public QueueDoubleLinkedListImpl<Integer> queue2; | |
public QueueDoubleLinkedListImpl<Integer> queue3; | |
@Before | |
public void setUp() throws QueueOverflowException{ | |
queue1 = new QueueDoubleLinkedListImpl<Integer>(6); | |
queue1.enqueue(1); | |
queue1.enqueue(2); | |
queue1.enqueue(3); | |
queue2 = new QueueDoubleLinkedListImpl<Integer>(2); | |
queue2.enqueue(1); | |
queue2.enqueue(2); | |
queue3 = new QueueDoubleLinkedListImpl<Integer>(3); | |
} | |
//MÉTODOS DE TESTE | |
@Test | |
public void testHead() { | |
try { | |
// check if 1 is on head of queue 1 | |
Assert.assertTrue(queue1.head() == 1); | |
// add 4 at queue 1 | |
queue1.enqueue(4); | |
// check if head is still 1 | |
Assert.assertTrue(queue1.head() == 1); | |
// remove one element from queue 1 | |
queue1.dequeue(); | |
// check if head is no longer 1 | |
Assert.assertFalse(queue1.head() == 1); | |
queue2.dequeue(); | |
queue2.dequeue(); | |
// check if head is null at queue 1, that is empty | |
Assert.assertTrue(queue2.head() == null); | |
} catch (Exception e) { | |
Assert.fail("Teste failed."); | |
} | |
} | |
@Test | |
public void testIsEmpty() { | |
try { | |
Assert.assertTrue(queue3.isEmpty()); | |
queue3.enqueue(1); | |
Assert.assertFalse(queue3.isEmpty()); | |
Assert.assertFalse(queue1.isEmpty()); | |
Assert.assertFalse(queue2.isEmpty()); | |
queue2.dequeue(); | |
queue2.dequeue(); | |
Assert.assertTrue(queue2.isEmpty()); | |
} catch (Exception e) { | |
Assert.fail("Test has failed."); | |
} | |
} | |
@Test | |
public void testIsFull() { | |
try { | |
Assert.assertFalse(queue3.isFull()); | |
Assert.assertFalse(queue1.isFull()); | |
queue1.enqueue(4); | |
queue1.enqueue(5); | |
queue1.enqueue(6); | |
Assert.assertTrue(queue1.isFull()); | |
Assert.assertTrue(queue2.isFull()); | |
queue2.dequeue(); | |
Assert.assertFalse(queue2.isFull()); | |
} catch (Exception e) { | |
Assert.fail("Test has failed."); | |
} | |
} | |
@Test | |
public void testEnqueue() { | |
try { | |
queue3.enqueue(1); | |
queue3.enqueue(2); | |
queue3.enqueue(3); | |
Assert.assertTrue(queue3.isFull()); | |
} catch (Exception e) { | |
Assert.fail("Test has failed."); | |
} | |
} | |
@Test(expected=QueueOverflowException.class) | |
public void testEnqueueComErro() throws QueueOverflowException { | |
queue2.enqueue(3); | |
} | |
@Test | |
public void testDequeue() { | |
try { | |
Assert.assertTrue(queue2.head().equals(1)); | |
queue2.dequeue(); | |
Assert.assertTrue(queue2.head().equals(2)); | |
queue2.dequeue(); | |
Assert.assertTrue(queue2.isEmpty()); | |
} catch (Exception e) { | |
Assert.fail("Test has failed."); | |
} | |
} | |
@Test(expected=QueueUnderflowException.class) | |
public void testDequeueComErro() throws QueueUnderflowException { | |
queue3.dequeue(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import java.util.Arrays; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class ItaloTestes { | |
private DoubleLinkedList<Integer> lista1; | |
private DoubleLinkedList<Integer> lista2; | |
private DoubleLinkedList<Integer> lista3; | |
private DoubleLinkedList<Integer> minhaListaVazia; | |
private DoubleLinkedList<Integer> minhaListaUnitaria; | |
private DoubleLinkedList<Integer> minhaListaComDoisElementos; | |
private DoubleLinkedList<Integer> minhaListaComTresElementos; | |
private DoubleLinkedList<Integer> minhaListaComElementosRepetidos; | |
private DoubleLinkedList<Integer> minhaListaElementosIguais; | |
@Before | |
public void setUp() throws Exception { | |
getImplementations(); | |
// Lista com 3 elementos. | |
lista1.insert(1); | |
lista1.insert(2); | |
lista1.insert(3); | |
// Lista com 1 elemento. | |
lista3.insert(1); | |
minhaListaElementosIguais.insert(10); | |
minhaListaElementosIguais.insert(10); | |
minhaListaElementosIguais.insert(10); | |
minhaListaComDoisElementos.insert(50); | |
minhaListaComDoisElementos.insert(30); | |
minhaListaComTresElementos.insert(14); | |
minhaListaComTresElementos.insert(8); | |
minhaListaComElementosRepetidos.insert(2); | |
minhaListaComElementosRepetidos.insert(2); | |
minhaListaComElementosRepetidos.insert(2); | |
minhaListaComElementosRepetidos.insert(2); | |
} | |
private void getImplementations(){ | |
lista1 = new DoubleLinkedListImpl(); | |
lista2 = new DoubleLinkedListImpl(); | |
lista3 = new DoubleLinkedListImpl(); | |
minhaListaVazia = new DoubleLinkedListImpl<Integer>(); | |
minhaListaUnitaria = new DoubleLinkedListImpl<Integer>(); | |
minhaListaComDoisElementos = new DoubleLinkedListImpl<Integer>(); | |
minhaListaComTresElementos = new DoubleLinkedListImpl<Integer>(); | |
minhaListaComElementosRepetidos = new DoubleLinkedListImpl<Integer>(); | |
minhaListaElementosIguais = new DoubleLinkedListImpl<Integer>(); | |
} | |
@Test | |
public void testIsEmpty() { | |
Assert.assertTrue(lista2.isEmpty()); | |
Assert.assertFalse(lista3.isEmpty()); | |
lista3.removeLast(); | |
Assert.assertTrue(lista3.isEmpty()); | |
lista3.insert(1); | |
Assert.assertFalse(lista3.isEmpty()); | |
lista3.removeFirst(); | |
Assert.assertTrue(lista3.isEmpty()); | |
lista3.insert(1); | |
Assert.assertFalse(lista3.isEmpty()); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.isEmpty()); | |
} | |
@Test | |
public void testIsEmpty_2() { | |
// Assert.assertFalse(minhaListaVazia.isEmpty()); // deve falhar | |
Assert.assertTrue(minhaListaVazia.isEmpty()); | |
lista3.removeLast(); | |
Assert.assertTrue(lista3.isEmpty()); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testSize() { | |
Assert.assertTrue(lista1.size() == 3); | |
Assert.assertTrue(lista2.size() == 0); | |
Assert.assertTrue(lista3.size() == 1); | |
lista3.removeLast(); | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insert(1); | |
lista3.removeFirst(); | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insert(1); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insertFirst(1); | |
Assert.assertTrue(lista3.size() == 1); | |
} | |
@Test | |
public void testSize_2() { | |
// Assert.assertEquals(2, lista1.size()); // deve dar falha | |
// apos dar falha, testar a linha abaixo (deve passar nos testes) | |
Assert.assertEquals(2, minhaListaComTresElementos.size()); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testSearch() { | |
Assert.assertTrue(lista1.search(1) == 1); | |
Assert.assertTrue(lista1.search(2) == 2); | |
Assert.assertTrue(lista1.search(3) == 3); | |
Assert.assertTrue(lista1.search(4) == null); | |
lista1.removeLast(); | |
Assert.assertTrue(lista1.search(3) == null); | |
lista1.removeFirst(); | |
Assert.assertTrue(lista1.search(1) == null); | |
Assert.assertTrue(lista2.search(1) == null); | |
Assert.assertTrue(lista3.search(1) == 1); | |
} | |
@Test | |
public void testSearch_2() { | |
Assert.assertEquals(10, (int) minhaListaElementosIguais.search(10)); | |
minhaListaElementosIguais.remove(10); | |
Assert.assertEquals(10, (int) minhaListaElementosIguais.search(10)); | |
minhaListaElementosIguais.remove(10); | |
Assert.assertEquals(10, (int) minhaListaElementosIguais.search(10)); | |
minhaListaElementosIguais.remove(10); | |
Assert.assertNull(minhaListaElementosIguais.search(10)); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testInsert() { | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.remove(1); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(null); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(1); | |
Assert.assertTrue(lista2.size() == 1); | |
//#-------------------------------------------- | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insert(1); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
Assert.assertTrue(list.last.getData() == 1); | |
list.removeFirst(); | |
Assert.assertTrue(list.size() == 0); | |
list.insert(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
Assert.assertTrue(list.last.getData() == 0); | |
list.insert(1); | |
Assert.assertTrue(list.last.getData() == 1); | |
list.insert(2); | |
Assert.assertTrue(list.last.getData() == 2); | |
Assert.assertTrue(list.last.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == 1); | |
} | |
@Test | |
public void testInsert_2() { | |
Assert.assertNull(minhaListaVazia.search(7)); | |
minhaListaVazia.insert(7); | |
Assert.assertEquals(7, (int) minhaListaVazia.search(7)); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testRemove() { | |
Assert.assertTrue(lista1.size() == 3); | |
lista1.remove(1); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(10); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(null); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(2); | |
Assert.assertTrue(lista1.size() == 1); | |
lista1.remove(3); | |
Assert.assertTrue(lista1.size() == 0); | |
//#--------------------------------------------------- | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insert(0); | |
list.insert(1); | |
list.insert(2); | |
list.insert(3); | |
list.remove(2); | |
Assert.assertTrue( list.head.next.next.getData() == 3 ); | |
Assert.assertTrue( list.last.previous.getData() == 1 ); | |
list.remove(0); | |
Assert.assertTrue(list.head.getData() == 1); | |
list.remove(3); | |
Assert.assertTrue(list.last.getData() == 1); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.last.previous.getData() == null); | |
Assert.assertTrue(list.head.next.getData() == null); | |
list.remove(1); | |
Assert.assertTrue(list.last.getData() == null); | |
Assert.assertTrue(list.head.getData() == null); | |
//#--------------------------------------------------- | |
list = new DoubleLinkedListImpl<Integer>(); | |
list.insert(1); | |
list.insert(2); | |
list.insert(3); | |
list.remove(1); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
list.insertFirst(1); | |
list.remove(3); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.last.getData() == 2); | |
list.insert(3); | |
list.remove(2); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.last.getData() == 3); | |
} | |
@Test | |
public void testRemove_2() { | |
lista3.remove(1); | |
Assert.assertTrue(lista3.search(10) == null); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testToArray() { | |
Assert.assertArrayEquals(new Integer[]{1, 2, 3}, lista1.toArray()); | |
Assert.assertArrayEquals(new Integer[]{}, lista2.toArray()); | |
Assert.assertArrayEquals(new Integer[]{1}, lista3.toArray()); | |
lista2.insert(1); | |
Assert.assertArrayEquals(new Integer[]{1}, lista2.toArray()); | |
lista2.remove(1); | |
Assert.assertArrayEquals(new Integer[]{}, lista2.toArray()); | |
lista3.removeFirst(); | |
Assert.assertArrayEquals(new Integer[]{}, lista3.toArray()); | |
lista3.insertFirst(1); | |
Assert.assertArrayEquals(new Integer[]{1}, lista3.toArray()); | |
lista3.removeLast(); | |
Assert.assertArrayEquals(new Integer[]{}, lista3.toArray()); | |
} | |
// Métodos de DoubleLinkedList | |
@Test | |
public void testInsertFirst(){ | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insertFirst(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.remove(1); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insertFirst(null); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insertFirst(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.insertFirst(0); | |
Assert.assertTrue(lista2.size() == 2); | |
//#--------------------------------------------------- | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insertFirst(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
list.insertFirst(1); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
list.insertFirst(2); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
} | |
@Test | |
public void testInsertFirst_2() { | |
minhaListaComTresElementos.insertFirst(9); | |
// deve falhar: | |
// Assert.assertNotEquals("[9, 14, 8]", | |
// minhaListaComTresElementos.toArray().toString()); | |
Assert.assertEquals("[9, 14, 8]", Arrays.toString(minhaListaComTresElementos.toArray())); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testRemoveFirst(){ | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insertFirst(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
list.insertFirst(1); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
list.insertFirst(2); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
list.removeFirst(); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.head.next.getData() == 0); | |
Assert.assertTrue(list.last.previous.previous.getData() == null); | |
Assert.assertTrue(list.size() == 2); | |
list.removeFirst(); | |
Assert.assertTrue(list.head.getData() == 0); | |
Assert.assertTrue(list.head.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == null); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == null); | |
Assert.assertTrue(list.head.getData() == null); | |
} | |
@Test | |
public void testRemoveFirst_2() { | |
minhaListaComTresElementos.removeFirst(); | |
// deve falhar | |
// Assert.assertEquals(14, (int)minhaListaComTresElementos.search(14)); | |
Assert.assertEquals("[8]", Arrays.toString(minhaListaComTresElementos.toArray())); | |
// Assert.fail("Not implemented!"); | |
} | |
@Test | |
public void testRemoveLast(){ | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insertFirst(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
list.insertFirst(1); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
list.insertFirst(2); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == 1); | |
Assert.assertTrue(list.last.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == 2); | |
Assert.assertTrue(list.size() == 2); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == 2); | |
Assert.assertTrue(list.last.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == null); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == null); | |
Assert.assertTrue(list.head.getData() == null); | |
} | |
@Test | |
public void testRemoveLast_2() { | |
minhaListaComElementosRepetidos.removeLast(); | |
Assert.assertTrue(minhaListaComElementosRepetidos.search(2) != null); | |
lista3.removeLast(); | |
Assert.assertTrue(lista3.isEmpty()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import static org.junit.Assert.*; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import adt.stack.StackDoubleLinkedListImpl; | |
import adt.stack.StackOverflowException; | |
import adt.stack.StackUnderflowException; | |
public class ItaloTestStack { | |
public StackDoubleLinkedListImpl<Integer> stack1; | |
public StackDoubleLinkedListImpl<Integer> stack2; | |
public StackDoubleLinkedListImpl<Integer> stack3; | |
@Before | |
public void setUp() throws StackOverflowException{ | |
stack1 = new StackDoubleLinkedListImpl<Integer>(6); | |
stack1.push(1); | |
stack1.push(2); | |
stack1.push(3); | |
stack2 = new StackDoubleLinkedListImpl<Integer>(2); | |
stack2.push(1); | |
stack2.push(2); | |
stack3 = new StackDoubleLinkedListImpl<Integer>(6); | |
} | |
//MÉTODOS DE TESTE | |
@Test | |
public void testTop() { | |
Assert.assertTrue(stack1.top().equals(3)); | |
Assert.assertTrue(stack2.top().equals(2)); | |
Assert.assertTrue(stack3.top() == null); | |
} | |
@Test | |
public void testIsEmpty() { | |
Assert.assertEquals(false, stack1.isEmpty()); | |
Assert.assertEquals(false, stack2.isEmpty()); | |
Assert.assertEquals(true, stack3.isEmpty()); | |
} | |
@Test | |
public void testIsFull() { | |
Assert.assertEquals(false, stack1.isFull()); | |
Assert.assertEquals(true, stack2.isFull()); | |
Assert.assertEquals(false, stack3.isFull()); | |
} | |
@Test | |
public void testPush() { | |
// test if some null element is added | |
try{ | |
stack3.push(null); | |
Assert.assertTrue(stack3.isEmpty()); | |
Assert.assertFalse(stack3.isFull()); | |
} catch(StackOverflowException e){ | |
Assert.fail(); | |
} | |
// normal push test | |
try { | |
stack1.push(4); | |
stack1.push(5); | |
stack1.push(6); | |
} catch (Exception e) { | |
Assert.fail(); | |
} | |
} | |
@Test(expected=StackOverflowException.class) | |
public void testPushComErro() throws StackOverflowException { | |
stack2.push(3); | |
} | |
@Test | |
public void testPop() { | |
try { | |
stack1.push(4); | |
stack1.push(5); | |
stack1.push(6); | |
Assert.assertEquals(true, stack1.isFull()); | |
Assert.assertTrue(stack1.pop().equals(6)); | |
Assert.assertTrue(stack1.pop().equals(5)); | |
Assert.assertTrue(stack1.pop().equals(4)); | |
Assert.assertTrue(stack1.pop().equals(3)); | |
Assert.assertTrue(stack1.pop().equals(2)); | |
Assert.assertTrue(stack1.pop().equals(1)); | |
stack1.pop(); | |
} catch (Exception e) { | |
Assert.assertEquals("Stack is empty", e.getMessage()); | |
} | |
} | |
@Test(expected=StackUnderflowException.class) | |
public void testPopComErro() throws StackUnderflowException { | |
stack3.pop(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class StudentDoubleLinkedListTest extends StudentLinkedListTest{ | |
private DoubleLinkedList<Integer> lista1; | |
private DoubleLinkedList<Integer> lista2; | |
private DoubleLinkedList<Integer> lista3; | |
@Before | |
public void setUp() throws Exception { | |
super.setUp(); | |
getImplementations(); | |
// Lista com 3 elementos. | |
lista1.insert(3); | |
lista1.insert(2); | |
lista1.insert(1); | |
// Lista com 1 elemento. | |
lista3.insert(1); | |
} | |
private void getImplementations(){ | |
//TODO O aluno deve ajustar aqui para instanciar sua implementação | |
lista1 = new DoubleLinkedListImpl<Integer>(); | |
lista2 = new DoubleLinkedListImpl<Integer>(); | |
lista3 = new DoubleLinkedListImpl<Integer>(); | |
} | |
// Métodos de DoubleLinkedList | |
@Test | |
public void testInsertFirst(){ | |
lista1.insertFirst(4); | |
Assert.assertArrayEquals(new Integer[] { 4, 3, 2, 1 }, lista1.toArray()); | |
} | |
@Test | |
public void testRemoveFirst(){ | |
lista1.removeFirst(); | |
Assert.assertArrayEquals(new Integer[] { 2, 1 }, lista1.toArray()); | |
} | |
@Test | |
public void testRemoveLast(){ | |
lista1.removeLast(); | |
Assert.assertArrayEquals(new Integer[] { 3, 2 }, lista1.toArray()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class StudentLinkedListTest { | |
private LinkedList<Integer> lista1; | |
private LinkedList<Integer> lista2; | |
@Before | |
public void setUp() throws Exception { | |
getImplementations(); | |
// Lista com 3 elementos. | |
lista1.insert(3); | |
lista1.insert(2); | |
lista1.insert(1); | |
} | |
private void getImplementations(){ | |
//TODO O aluno deve ajustar aqui para instanciar sua implementação | |
lista1 = new SingleLinkedListImpl<>(); | |
lista2 = new SingleLinkedListImpl<>(); | |
} | |
@Test | |
public void testIsEmpty() { | |
Assert.assertFalse(lista1.isEmpty()); | |
Assert.assertTrue(lista2.isEmpty()); | |
} | |
@Test | |
public void testSize() { | |
Assert.assertEquals(3, lista1.size()); | |
Assert.assertEquals(0, lista2.size()); | |
} | |
@Test | |
public void testSearch() { | |
Assert.assertTrue(2 == lista1.search(2)); | |
Assert.assertNull(lista1.search(4)); | |
Assert.assertFalse(3 == lista1.search(2)); | |
} | |
@Test | |
public void testInsert() { | |
Assert.assertEquals(3, lista1.size()); | |
lista1.insert(5); | |
lista1.insert(7); | |
Assert.assertEquals(5, lista1.size()); | |
Assert.assertEquals(0, lista2.size()); | |
lista2.insert(4); | |
lista2.insert(7); | |
Assert.assertEquals(2, lista2.size()); | |
} | |
@Test | |
public void testRemove() { | |
Assert.assertEquals(3, lista1.size()); | |
lista1.remove(2); | |
lista1.remove(1); | |
Assert.assertEquals(1, lista1.size()); | |
Assert.assertNotEquals(3, lista1.size()); | |
lista1.remove(4); | |
lista1.remove(2); | |
lista1.remove(1); | |
Assert.assertEquals(1, lista1.size()); | |
} | |
@Test | |
public void testToArray() { | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
Assert.assertArrayEquals(new Integer[] { 3, 2, 1 }, lista1.toArray()); | |
} | |
//========================================================================= | |
@Test | |
public void testIsEmpty2() { | |
Assert.assertFalse(lista1.isEmpty()); | |
lista1.remove(1); | |
lista1.remove(2); | |
lista1.remove(3); | |
Assert.assertTrue(lista1.isEmpty()); | |
Assert.assertTrue(lista2.isEmpty()); | |
} | |
@Test | |
public void testSize2() { | |
Assert.assertTrue(lista1.size() == 3); | |
lista1.remove(1); | |
lista1.remove(2); | |
lista1.remove(3); | |
Assert.assertTrue(lista1.size() == 0); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.remove(1); | |
Assert.assertTrue(lista2.size() == 0); | |
} | |
@Test | |
public void testSearch2() { | |
Assert.assertTrue(lista1.search(1) == 1); | |
Assert.assertTrue(lista1.search(2) == 2); | |
Assert.assertTrue(lista1.search(3) == 3); | |
Assert.assertTrue(lista1.search(4) == null); | |
Assert.assertTrue(lista2.search(1) == null); | |
} | |
@Test | |
public void testInsert2() { | |
lista2.insert(10); | |
Assert.assertTrue(lista2.size() == 1); | |
lista1.insert(10); | |
Assert.assertTrue(lista1.size() == 4); | |
lista1.insert(null); | |
Assert.assertTrue(lista1.size() == 4); | |
} | |
@Test | |
public void testInsertComparative() { | |
Integer[] array = new Integer[50]; | |
int j; | |
for(j = 0; j < 50; j++){ | |
lista2.insert(j); | |
array[j] = j; | |
Assert.assertTrue(lista2.search(j).equals(j)); | |
} | |
for(int i = 0; i < array.length; i++){ | |
Assert.assertEquals(lista2.search(i), array[i]); | |
} | |
} | |
@Test | |
public void testRemove2() { | |
lista1.remove(1); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(10); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(null); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(2); | |
Assert.assertTrue(lista1.size() == 1); | |
lista1.remove(3); | |
Assert.assertTrue(lista1.size() == 0); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
lista2.remove(2); | |
Assert.assertArrayEquals(new Integer[] {}, lista2.toArray()); | |
} | |
@Test | |
public void testRemoveComparative() { | |
Integer[] array = new Integer[10]; | |
int j; | |
for(j = 0; j < 10; j++) { | |
lista2.insert(j); | |
Assert.assertTrue(lista2.search(j).equals(j)); | |
} | |
for(int i = 0; i < 5; i++) { | |
lista2.remove(i); | |
Assert.assertFalse(new Integer(i).equals(lista2.search(i))); | |
} | |
for(int i = 9; i > 5; i--) { | |
lista2.remove(i); | |
Assert.assertFalse(new Integer(i).equals(lista2.search(i))); | |
} | |
lista2.remove(5); | |
Assert.assertTrue(lista2.isEmpty()); | |
} | |
@Test | |
public void testToArray2() { | |
Assert.assertArrayEquals(new Integer[]{3,2,1}, lista1.toArray()); | |
Assert.assertArrayEquals(new Integer[]{}, lista2.toArray()); | |
lista2.insert(1); | |
Assert.assertArrayEquals(new Integer[]{1}, lista2.toArray()); | |
lista2.remove(1); | |
Assert.assertArrayEquals(new Integer[]{}, lista2.toArray()); | |
} | |
// ## TESTS ON STREAMS ## ------------------- | |
@Test | |
public void streamTest1() { | |
LinkedList<Integer> array = new SingleLinkedListImpl<Integer>(); | |
Assert.assertTrue(array.isEmpty()); | |
Assert.assertEquals(array.size(), 0); | |
array.insert(5); | |
Assert.assertFalse(array.isEmpty()); | |
Assert.assertEquals(array.size(), 1); | |
} | |
@Test | |
public void streamTest2() { | |
LinkedList<Integer> vector = new SingleLinkedListImpl<Integer>(); | |
Integer[] array = new Integer[]{5, 3, 9}; | |
vector.insert(5); | |
vector.insert(3); | |
vector.insert(9); | |
Assert.assertArrayEquals(array, vector.toArray()); | |
} | |
@Test | |
public void streamTest3() { | |
LinkedList<Integer> array = new SingleLinkedListImpl<Integer>(); | |
array.insert(5); | |
array.insert(3); | |
array.insert(9); | |
array.insert(12); | |
array.remove(3); | |
Assert.assertArrayEquals(new Integer[]{5, 9, 12}, array.toArray()); | |
Assert.assertFalse(array.isEmpty()); | |
Assert.assertEquals(array.size(), 3); | |
array.remove(3); | |
Assert.assertArrayEquals(new Integer[]{5, 9, 12}, array.toArray()); | |
Assert.assertEquals(array.size(), 3); | |
array.remove(5); | |
Assert.assertArrayEquals(new Integer[]{9, 12}, array.toArray()); | |
Assert.assertEquals(array.size(), 2); | |
array.remove(9); | |
Assert.assertArrayEquals(new Integer[]{12}, array.toArray()); | |
Assert.assertEquals(array.size(), 1); | |
array.remove(12); | |
Assert.assertEquals(array.size(), 0); | |
Assert.assertTrue(array.isEmpty()); | |
Assert.assertArrayEquals(new Integer[]{}, array.toArray()); | |
array.remove(17); | |
Assert.assertArrayEquals(new Integer[]{}, array.toArray()); | |
} | |
@Test | |
public void streamTest4() { | |
LinkedList<String> array = new SingleLinkedListImpl<String>(); | |
array.insert("rafael"); | |
array.insert("lapis"); | |
array.insert("borracha"); | |
array.insert("papel"); | |
array.insert("regua"); | |
Assert.assertEquals(array.search("rafael"), "rafael"); | |
Assert.assertEquals(array.search("regua"), "regua"); | |
Assert.assertEquals(array.search("caneta"), null); | |
} | |
@Test | |
public void streamTest5() { | |
SingleLinkedListImpl<Integer> testando = new SingleLinkedListImpl<Integer>(); | |
Assert.assertTrue(testando.size() == 0); | |
Assert.assertTrue(testando.isEmpty()); | |
testando.insert(1); | |
testando.insert(2); | |
testando.insert(3); | |
testando.insert(null); | |
Assert.assertTrue(testando.size() == 3); | |
Assert.assertFalse(testando.isEmpty()); | |
Assert.assertTrue(2 == testando.getHead().getNext().getData()); | |
Assert.assertTrue(testando.search(4) == null); | |
Assert.assertTrue(testando.search(null) == null); | |
Assert.assertTrue(testando.search(2) == 2); | |
testando.remove(null); | |
testando.remove(5); | |
testando.remove(2); | |
testando.insert(5); | |
Assert.assertTrue(testando.size() == 3); | |
Integer[] array = {1,3,5}; | |
Assert.assertArrayEquals( array , testando.toArray()); | |
} | |
@Test | |
public void streamTest6() { | |
lista2 = new SingleLinkedListImpl(); | |
Integer[] array = {6,7,1,3,4,2,10}; | |
Assert.assertTrue(lista2.isEmpty()); | |
Assert.assertTrue(lista2.size()==0); | |
lista2.insert(5); | |
Assert.assertFalse(lista2.isEmpty()); | |
Assert.assertTrue(lista2.size()==1); | |
Assert.assertTrue(lista2.search(6)==null); | |
Assert.assertTrue(lista2.search(5)==5); | |
lista2.insert(6); | |
Assert.assertTrue(lista2.search(6)==6); | |
Assert.assertTrue(lista2.search(7)==null); | |
lista2.insert(7); | |
Assert.assertTrue(lista2.search(7)==7); | |
lista2.remove(5); | |
Assert.assertTrue(lista2.search(5)==null); | |
lista2.insert(1); | |
lista2.insert(3); | |
lista2.insert(4); | |
lista2.insert(2); | |
lista2.insert(10); | |
Assert.assertArrayEquals(array, lista2.toArray()); | |
} | |
@Test | |
public void streamTest7() { | |
lista2.insert(2); | |
lista2.remove(1); | |
Assert.assertFalse(lista2.isEmpty()); | |
lista2.remove(2); | |
Assert.assertTrue(lista2.isEmpty()); | |
lista2.insert(2); | |
lista2.insert(3); | |
lista2.insert(5); | |
lista2.remove(3); | |
Integer[] array = {2,5}; | |
Assert.assertArrayEquals(array, lista2.toArray()); | |
} | |
@Test | |
public void streamTest8() { | |
lista2.insert(2); | |
lista2.insert(3); | |
lista2.insert(5); | |
Assert.assertTrue(lista2.search(2) == 2); | |
Assert.assertTrue(lista2.search(3) == 3); | |
lista2.remove(3); | |
Assert.assertTrue(lista2.search(5) == 5); | |
Assert.assertTrue(lista2.search(3) == null); | |
} | |
@Test | |
public void streamTest9() { | |
SingleLinkedListImpl<Integer> array = new SingleLinkedListImpl<Integer>(); | |
array.insert(1); | |
array.insert(2); | |
array.insert(3); | |
Assert.assertTrue(array.size() == 3); | |
array.remove(3); | |
Assert.assertTrue(array.getHead().getData() == 1); | |
Assert.assertTrue(array.getHead().getNext().getNext().getData() == null); | |
array.remove(1); | |
Assert.assertTrue(array.getHead().getData() == 2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt.linkedList; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import adt.queue.QueueDoubleLinkedListImpl; | |
import adt.queue.QueueOverflowException; | |
public class TestQueue { | |
private DoubleLinkedList<Integer> lista1; | |
private DoubleLinkedList<Integer> lista2; | |
private DoubleLinkedList<Integer> lista3; | |
private QueueDoubleLinkedListImpl<Integer> queue1; | |
@Before | |
public void setUp() throws Exception { | |
getImplementations(); | |
// Lista com 3 elementos. | |
lista1.insert(1); | |
lista1.insert(2); | |
lista1.insert(3); | |
// Lista com 1 elemento. | |
lista3.insert(1); | |
queue1 = new QueueDoubleLinkedListImpl<Integer>(5); | |
queue1.enqueue(5); | |
queue1.enqueue(1); | |
queue1.enqueue(3); | |
} | |
private void getImplementations(){ | |
lista1 = new DoubleLinkedListImpl(); | |
lista2 = new DoubleLinkedListImpl(); | |
lista3 = new DoubleLinkedListImpl(); | |
} | |
@Test | |
public void testEnqueue() throws QueueOverflowException { | |
queue1.enqueue(4); | |
queue1.enqueue(null); | |
} | |
@Test | |
public void testIsEmpty() { | |
Assert.assertTrue(lista2.isEmpty()); | |
Assert.assertFalse(lista3.isEmpty()); | |
lista3.removeLast(); | |
Assert.assertTrue(lista3.isEmpty()); | |
lista3.insert(1); | |
Assert.assertFalse(lista3.isEmpty()); | |
lista3.removeFirst(); | |
Assert.assertTrue(lista3.isEmpty()); | |
lista3.insert(1); | |
Assert.assertFalse(lista3.isEmpty()); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.isEmpty()); | |
} | |
@Test | |
public void testSize() { | |
Assert.assertTrue(lista1.size() == 3); | |
Assert.assertTrue(lista2.size() == 0); | |
Assert.assertTrue(lista3.size() == 1); | |
lista3.removeLast(); | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insert(1); | |
lista3.removeFirst(); | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insert(1); | |
lista3.remove(1); | |
Assert.assertTrue(lista3.size() == 0); | |
lista3.insertFirst(1); | |
Assert.assertTrue(lista3.size() == 1); | |
} | |
@Test | |
public void testSearch() { | |
Assert.assertTrue(lista1.search(1) == 1); | |
Assert.assertTrue(lista1.search(2) == 2); | |
Assert.assertTrue(lista1.search(3) == 3); | |
Assert.assertTrue(lista1.search(4) == null); | |
lista1.removeLast(); | |
Assert.assertTrue(lista1.search(3) == null); | |
lista1.removeFirst(); | |
Assert.assertTrue(lista1.search(1) == null); | |
Assert.assertTrue(lista2.search(1) == null); | |
Assert.assertTrue(lista3.search(1) == 1); | |
} | |
@Test | |
public void testInsert() { | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.remove(1); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(null); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insert(1); | |
Assert.assertTrue(lista2.size() == 1); | |
//#-------------------------------------------- | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insert(1); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
Assert.assertTrue(list.last.getData() == 1); | |
list.removeFirst(); | |
Assert.assertTrue(list.size() == 0); | |
list.insert(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
Assert.assertTrue(list.last.getData() == 0); | |
list.insert(1); | |
Assert.assertTrue(list.last.getData() == 1); | |
list.insert(2); | |
Assert.assertTrue(list.last.getData() == 2); | |
Assert.assertTrue(list.last.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == 1); | |
} | |
@Test | |
public void testRemove() { | |
Assert.assertTrue(lista1.size() == 3); | |
lista1.remove(1); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(10); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(null); | |
Assert.assertTrue(lista1.size() == 2); | |
lista1.remove(2); | |
Assert.assertTrue(lista1.size() == 1); | |
lista1.remove(3); | |
Assert.assertTrue(lista1.size() == 0); | |
//#--------------------------------------------------- | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insert(0); | |
list.insert(1); | |
list.insert(2); | |
list.insert(3); | |
list.remove(2); | |
Assert.assertTrue( list.head.next.next.getData() == 3 ); | |
Assert.assertTrue( list.last.previous.getData() == 1 ); | |
list.remove(0); | |
Assert.assertTrue(list.head.getData() == 1); | |
list.remove(3); | |
Assert.assertTrue(list.last.getData() == 1); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.last.previous.getData() == null); | |
Assert.assertTrue(list.head.next.getData() == null); | |
list.remove(1); | |
Assert.assertTrue(list.last.getData() == null); | |
Assert.assertTrue(list.head.getData() == null); | |
//#--------------------------------------------------- | |
list = new DoubleLinkedListImpl<Integer>(); | |
list.insert(1); | |
list.insert(2); | |
list.insert(3); | |
list.remove(1); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
list.insertFirst(1); | |
list.remove(3); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.last.getData() == 2); | |
list.insert(3); | |
list.remove(2); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.last.getData() == 3); | |
} | |
@Test | |
public void testToArray() { | |
Assert.assertArrayEquals(new Integer[]{1, 2, 3}, lista1.toArray()); | |
Assert.assertArrayEquals(new Integer[]{}, lista2.toArray()); | |
Assert.assertArrayEquals(new Integer[]{1}, lista3.toArray()); | |
lista2.insert(1); | |
Assert.assertArrayEquals(new Integer[]{1}, lista2.toArray()); | |
lista2.remove(1); | |
Assert.assertArrayEquals(new Integer[]{}, lista2.toArray()); | |
lista3.removeFirst(); | |
Assert.assertArrayEquals(new Integer[]{}, lista3.toArray()); | |
lista3.insertFirst(1); | |
Assert.assertArrayEquals(new Integer[]{1}, lista3.toArray()); | |
lista3.removeLast(); | |
Assert.assertArrayEquals(new Integer[]{}, lista3.toArray()); | |
} | |
// Métodos de DoubleLinkedList | |
@Test | |
public void testInsertFirst(){ | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insertFirst(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.remove(1); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insertFirst(null); | |
Assert.assertTrue(lista2.size() == 0); | |
lista2.insertFirst(1); | |
Assert.assertTrue(lista2.size() == 1); | |
lista2.insertFirst(0); | |
Assert.assertTrue(lista2.size() == 2); | |
//#--------------------------------------------------- | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insertFirst(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
list.insertFirst(1); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
list.insertFirst(2); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
} | |
@Test | |
public void testRemoveFirst(){ | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insertFirst(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
list.insertFirst(1); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
list.insertFirst(2); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
list.removeFirst(); | |
Assert.assertTrue(list.head.getData() == 1); | |
Assert.assertTrue(list.head.next.getData() == 0); | |
Assert.assertTrue(list.last.previous.previous.getData() == null); | |
Assert.assertTrue(list.size() == 2); | |
list.removeFirst(); | |
Assert.assertTrue(list.head.getData() == 0); | |
Assert.assertTrue(list.head.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == null); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == null); | |
Assert.assertTrue(list.head.getData() == null); | |
} | |
@Test | |
public void testRemoveLast(){ | |
DoubleLinkedListImpl<Integer> list = new DoubleLinkedListImpl<Integer>(); | |
Assert.assertTrue(list.size() == 0); | |
list.insertFirst(0); | |
Assert.assertTrue(list.getHead().getData() == 0); | |
list.insertFirst(1); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 1); | |
list.insertFirst(2); | |
Assert.assertTrue(list.last.getData() == 0); | |
Assert.assertTrue(list.getHead().getData() == 2); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == 1); | |
Assert.assertTrue(list.last.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == 2); | |
Assert.assertTrue(list.size() == 2); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == 2); | |
Assert.assertTrue(list.last.next.getData() == null); | |
Assert.assertTrue(list.last.previous.getData() == null); | |
list.removeLast(); | |
Assert.assertTrue(list.last.getData() == null); | |
Assert.assertTrue(list.head.getData() == null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment