Created
April 24, 2015 11:18
-
-
Save delucas/e0759b2251177a35d4a7 to your computer and use it in GitHub Desktop.
Ejemplos de uso de Arrays en Java - UNTreF
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
import org.junit.Assert; | |
import org.junit.Test; | |
public class ArreglosTests { | |
@Test | |
public void quePuedoCrearloExplicitamente(){ | |
int[] edades = {22, 29, 27, 25, 21, 23, 25, 27}; | |
Assert.assertNotNull(edades); | |
} | |
@Test | |
public void quePuedoRecorrerElArray(){ | |
int[] edades = {22, 29, 27, 25, 21, 23, 25, 27}; | |
int sumaEdades = 0; | |
for(int edad : edades) { | |
sumaEdades += edad; | |
} | |
double edadPromedio = sumaEdades / edades.length; | |
Assert.assertEquals(24, edadPromedio, 0); | |
} | |
@Test | |
public void quePuedoCambiarUnaEdad(){ | |
int[] edades = {22, 29, 27, 25, 21, 23, 25, 27}; | |
Assert.assertEquals(29, edades[1]); | |
edades[1] = 32; | |
Assert.assertEquals(32, edades[1]); | |
} | |
@Test | |
public void quePuedoCrearloDeOtraManera(){ | |
int[] edades = new int[3]; | |
edades[0] = 1; | |
edades[1] = 1; | |
edades[2] = 1; | |
} | |
@Test(expected=IndexOutOfBoundsException.class) | |
public void quePuedoSalirDeRango(){ | |
int[] edades = new int[3]; | |
edades[3] = 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment