Advertisement
fmbalvarez

Guía 6 - Ejercicio 5 - Cubo

Oct 20th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1.  
  2. public class Cubo {
  3.    
  4.     int lado;
  5.    
  6.     public Cubo(int lado){
  7.        
  8.         this.lado = lado;
  9.     }
  10.    
  11.     public int obtenerLado(){
  12.        
  13.         return (lado);
  14.     }
  15.    
  16.     public void setLongitudLado(int lado){
  17.        
  18.         if (lado > 0){
  19.            
  20.             this.lado = lado;
  21.         }
  22.     }
  23.    
  24.     public int getSuperficieCara(){
  25.        
  26.         return (lado*4);
  27.     }
  28.    
  29.     public int getVolumen(){
  30.        
  31.         return (lado*lado*lado);
  32.     }
  33. }
  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.  
  65.  
  66.  
  67. import org.junit.Test;
  68. import org.junit.Assert;
  69.  
  70. public class PruebaCubo {
  71.    
  72.     @Test
  73.     public void ladoNegativo(){
  74.        
  75.         Cubo cubo = new Cubo(5);
  76.         cubo.setLongitudLado(-5);
  77.        
  78.         int longitudModificada = cubo.obtenerLado();
  79.        
  80.         Assert.assertEquals(5, longitudModificada);
  81.     }
  82.    
  83.     @Test
  84.     public void calcularSuperficie(){
  85.        
  86.         Cubo cubo = new Cubo(5);
  87.        
  88.         int superficie = cubo.getSuperficieCara();
  89.        
  90.         Assert.assertEquals(20, superficie);
  91.     }
  92.    
  93.     @Test
  94.     public void calcularVolumen(){
  95.        
  96.         Cubo cubo = new Cubo(5);
  97.        
  98.         int superficie = cubo.getVolumen();
  99.                
  100.         Assert.assertEquals(125, superficie);
  101.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement