Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement