Skip to content

Instantly share code, notes, and snippets.

@delucas
Created April 24, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delucas/e0759b2251177a35d4a7 to your computer and use it in GitHub Desktop.
Save delucas/e0759b2251177a35d4a7 to your computer and use it in GitHub Desktop.
Ejemplos de uso de Arrays en Java - UNTreF
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