The following method performs a removal of an element at a pre-defined position in the test class but does not appear to be working even though it has no syntax errors and errors in the test done by the teacher.
public void removerPosicao(int posicao){
try {
if(posicao == 0){
removerPrimeiro();
}else if(posicao == (getTamanho()-1)){
removerUltimo();
}else{
Node aux = inicio;
Node ant = aux;
int posicao_atual = 0;
while(posicao > posicao_atual){
ant = aux;
aux = aux.getProximo();
posicao_atual++;
}
ant.setProximo(null);
tamanho--;
}
} catch (Exception e){
System.out.println("Erro:" + e + ". Inserir posicao valida !");
}
}
@Test
public void testarRemoverPosicao(){
iniciarLista();
for(int i = 0; i < 3; i++){
lista.removerPosicao(1);
System.out.println(lista.toString());
}
}
Terminal output:
72 2 16 74
Expected output:
72 2 16 74
72 16 74
72 74
72
(always removing the element that is in position 1)