Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## src

Mantenha aqui todo o seu código fonte .java do projeto.
22 changes: 15 additions & 7 deletions src/Hora.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@ private boolean ehValida() {
* @return TRUE se esta hora está à frente no relógio, FALSE caso contrário.
*/
public boolean estahNaFrenteDe(Hora outra){
if(this.horas > outra.horas)
return true;
else if(this.minutos > outra.minutos)
return true;
else if(this.segundos > outra.segundos)
return true;
int diferenca = this.horas - outra.horas;
if(diferenca == 0){
diferenca = this.minutos - outra.minutos;
if (diferenca == 0) {
diferenca = this.segundos - outra.segundos;
}
}
return (diferenca > 0);
// if(this.horas > outra.horas)
// return true;
// else if(this.minutos > outra.minutos)
// return true;
// else if(this.segundos > outra.segundos)
// return true;

return false;
// return false;
}

/**
Expand Down
34 changes: 34 additions & 0 deletions src/HoraTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class HoraTest {

@Test
public void mostraHoraFormatadaCorretamente(){
Hora hora = new Hora(17,56,25);

String formatada = hora.horaFormatada();

assertEquals("17:56:25", formatada);

}

@Test
public void verificarHoraAdiantadaCorretamente(){
Hora hora = new Hora(18, 9, 15);
Hora outraHora = new Hora(10, 0, 0);
boolean adiantada = hora.estahNaFrenteDe(outraHora);
assertTrue(adiantada);
}

@Test
public void verificarHoraAtrasadaCorretamente(){
Hora hora = new Hora(18, 9, 15);
Hora outraHora = new Hora(20, 0, 0);
boolean adiantada = hora.estahNaFrenteDe(outraHora);
assertFalse(adiantada);
}
}