Advertisement
fmbalvarez

Guía 6 - Ejercicio 5 - Nota

Oct 20th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1.  
  2. public class Nota {
  3.    
  4.     int valorInicial;
  5.    
  6.     Nota(int valorInicial){
  7.        
  8.         if (valorInicial >= 0 && valorInicial <=10){
  9.            
  10.             this.valorInicial = valorInicial;  
  11.         }  
  12.     }
  13.    
  14.     int getValor(){
  15.        
  16.         return valorInicial;   
  17.     }
  18.    
  19.     boolean aprobado(){
  20.        
  21.         return (valorInicial >= 4);
  22.     }
  23.    
  24.     boolean desaprobado(){
  25.        
  26.         return (valorInicial <= 4);
  27.     }
  28.    
  29.     void recuperar(int nuevoValor){
  30.        
  31.         if (valorInicial < 4 && nuevoValor > valorInicial && nuevoValor >= 0 && nuevoValor <= 10){
  32.            
  33.             valorInicial = nuevoValor; 
  34.         }
  35.     }
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. import org.junit.Test;
  65. import org.junit.Assert;
  66.  
  67. public class PruebaNota {
  68.    
  69.     @Test
  70.     public void valorInicialNoCumpleCondiciones(){
  71.        
  72.         Nota nota = new Nota(15);
  73.        
  74.         int valorInicial = nota.getValor();
  75.        
  76.         Assert.assertEquals(0, valorInicial);
  77.     }
  78.    
  79.     @Test
  80.     public void pruebaRecuperarYAprobar(){
  81.        
  82.         Nota nota = new Nota(2);
  83.         nota.recuperar(7);
  84.        
  85.         Assert.assertTrue(nota.aprobado());
  86.     }
  87.    
  88.     @Test
  89.     public void pruebaRecuperarYDesaprobar(){
  90.        
  91.         Nota nota = new Nota(2);
  92.         nota.recuperar(1);
  93.        
  94.         int valorInicial = nota.getValor();
  95.        
  96.         Assert.assertEquals(2, valorInicial);
  97.     }
  98.    
  99.     @Test
  100.     public void recuperaYNuevoValorNoCumpleCondiciones(){
  101.        
  102.         Nota nota = new Nota(2);
  103.         nota.recuperar(12);
  104.        
  105.         int valorInicial = nota.getValor();
  106.        
  107.         Assert.assertEquals(2, valorInicial);
  108.     }
  109.    
  110.     @Test
  111.     public void recuperarSiAprobe(){
  112.        
  113.         Nota nota = new Nota(4);
  114.         nota.recuperar(8);
  115.        
  116.         int valor = nota.getValor();
  117.        
  118.         Assert.assertEquals(4, valor);
  119.     }
  120.    
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement