daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest May 16th, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package calculator;
  2.  
  3. import calculator.CalculatorController;
  4. import calculator.CalculatorModel;
  5. import junit.framework.TestCase;
  6.  
  7.  
  8. public class CalculatorControllerTest extends TestCase {
  9.  
  10.     CalculatorModel model = new CalculatorModel();
  11.     Calculation calculation = new StandardCalculation();
  12.     CalculatorController controller;
  13.    
  14.     public void setUp() {
  15.          controller = new CalculatorController(model, calculation);    
  16.     }
  17.     public void testItShouldInitializeToZero() throws Exception {
  18.         controller.push('C');
  19.         assertEquals("0.", model.getDisplay());
  20.     }
  21.    
  22.     public void testItShouldConcatenateTwoNumberPresses() {
  23.         controller.push('1');
  24.         controller.push('2');
  25.         assertEquals("12.", model.getDisplay());
  26.     }
  27.    
  28.     public void testItShouldConcatenateThreeNumberPresses() {
  29.         bulkPush("369");
  30.         assertEquals("369.", model.getDisplay());
  31.     }
  32.    
  33.     public void testItShouldSupportDecimalPoint() {
  34.         bulkPush("4.7");
  35.         assertEquals("4.7", model.getDisplay());
  36.     }
  37.    
  38.     public void testItShouldNotCareAboutSecondDecimalPoint() {
  39.         bulkPush("4.7..");
  40.         assertEquals("4.7", model.getDisplay());
  41.     }
  42.    
  43.     public void testDoPlus() {
  44.         bulkPush("4+5=");
  45.         assertEquals("9.", model.getDisplay());
  46.     }
  47.    
  48.     public void testDoMinus() {
  49.         bulkPush("2-4=");
  50.         assertEquals("-2.", model.getDisplay());
  51.     }
  52.    
  53.     public void testDoMultiply() {
  54.         bulkPush("2*4=");
  55.         assertEquals("8.", model.getDisplay());
  56.  
  57.     }
  58.    
  59.     public void testDoDivision() {
  60.         bulkPush("2/4=");
  61.         assertEquals("0.5", model.getDisplay());
  62.  
  63.     }
  64.    
  65.     public void testPutSignal() {
  66.         controller.push('2');
  67.         controller.push('±');
  68.         assertEquals("-2.", model.getDisplay());
  69.        
  70.     }
  71.    
  72.     public void testDoDivisionWithOtherSymbol() {
  73.         bulkPush("2÷4=");
  74.         assertEquals("0.5", model.getDisplay());
  75.  
  76.     }
  77.    
  78.     public void testGetValueAfterSign() {
  79.         controller.push('2');
  80.         controller.push('+');      
  81.         assertEquals("2.", model.getDisplay());
  82.     }
  83.    
  84.  
  85.     public void testDoSquareRoot() {
  86.         bulkPush("4√2=");
  87.         assertEquals("2.", model.getDisplay());
  88.     }
  89.    
  90.     public void testDoPower() {
  91.         bulkPush("4^4=");      
  92.         assertEquals("256.", model.getDisplay());
  93.     }
  94.    
  95.     private void bulkPush(String push) {
  96.         char[] list = push.toCharArray();
  97.         for (int i = 0; i < list.length; i++) {
  98.             controller.push(list[i]);
  99.            
  100.         }
  101.     }
  102.    
  103. }
RAW Paste Data
Top