Created
April 26, 2013 23:00
-
-
Save delucas/5471002 to your computer and use it in GitHub Desktop.
UNTreF - Días Lluviosos, ejemplo de clase 25/04/2013
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 ar.edu.untref.lp1; | |
public class DiasLluviosos { | |
private int[] lluviasDiarias = new int[30]; | |
public void setLluviaDiaria(int dia, int lluviaDiaria) { | |
if (dia < 1 || dia > 30 ) { | |
throw new Error("El mes tiene entre 1 y 30 días"); | |
} | |
this.lluviasDiarias[dia - 1] = lluviaDiaria; | |
} | |
public double promedioLluvia() { | |
int suma = 0; | |
for (int i = 0; i < this.lluviasDiarias.length; i++) { | |
suma += this.lluviasDiarias[i]; | |
} | |
return suma / this.lluviasDiarias.length; | |
} | |
} |
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 ar.edu.untref.lp1; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class DiasLluviososTests { | |
@Test | |
public void testQueSinLluviasPromedioCero() { | |
DiasLluviosos diasLluviosos = new DiasLluviosos(); | |
double promedio = diasLluviosos.promedioLluvia(); | |
Assert.assertEquals("Sin lluvias es cero", 0.0, promedio , 0.0); | |
} | |
@Test | |
public void testQueConLluviasPromedioValido() { | |
DiasLluviosos diasLluviosos = new DiasLluviosos(); | |
for (int i = 1; i <= 30; i++) { | |
diasLluviosos.setLluviaDiaria(i, 3); | |
} | |
double promedio = diasLluviosos.promedioLluvia(); | |
Assert.assertEquals("Con lluvias es tres", 3.0, promedio , 0.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment