Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3.  
  4.  
  5. public class ArreglosTests {
  6.  
  7. @Test
  8. public void quePuedoCrearloExplicitamente(){
  9.  
  10. int[] edades = {22, 29, 27, 25, 21, 23, 25, 27};
  11. Assert.assertNotNull(edades);
  12.  
  13. }
  14.  
  15. @Test
  16. public void quePuedoRecorrerElArray(){
  17.  
  18. int[] edades = {22, 29, 27, 25, 21, 23, 25, 27};
  19.  
  20. int sumaEdades = 0;
  21.  
  22. for(int edad : edades) {
  23. sumaEdades += edad;
  24. }
  25.  
  26. double edadPromedio = sumaEdades / edades.length;
  27.  
  28. Assert.assertEquals(24, edadPromedio, 0);
  29.  
  30. }
  31.  
  32. @Test
  33. public void quePuedoCambiarUnaEdad(){
  34.  
  35. int[] edades = {22, 29, 27, 25, 21, 23, 25, 27};
  36.  
  37. Assert.assertEquals(29, edades[1]);
  38. edades[1] = 32;
  39. Assert.assertEquals(32, edades[1]);
  40. }
  41.  
  42. @Test
  43. public void quePuedoCrearloDeOtraManera(){
  44.  
  45. int[] edades = new int[3];
  46. edades[0] = 1;
  47. edades[1] = 1;
  48. edades[2] = 1;
  49.  
  50. }
  51.  
  52. @Test(expected=IndexOutOfBoundsException.class)
  53. public void quePuedoSalirDeRango(){
  54.  
  55. int[] edades = new int[3];
  56. edades[3] = 10;
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement