0
The following method performs a removal of an element at a pre-defined position in the test class but appears not to be working even if there are no syntax errors and errors in the teacher’s test.
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 exit :
72 2 16 74
Expected exit :
72 2 16 74
72 16 74
72 74
72
(always removing the element that is in position 1)
"It appears not to be working". Why?
– Jéf Bueno
remove at start : 28 60 90 89 / 60 90 89 / 90 89 / 89 remove at end : 14 11 48 5 / 14 11 48 / 14 11 / 14 remove at position 1 : 72 2 16 74. This is what appears in the terminal of the tests of the 3 methods.
– A. Fernando
he would have to gradually decrease the list equal to the other 2 methods by removing only the element q would be at position 1 ? remove at position 1 : 72 2 16 74 / 72 16 74 / 72 74 / 72.
– A. Fernando
You can post your complete code so that it is compilable?
– Victor Stafusa