SHARE
TWEET

Untitled

a guest Feb 16th, 2020 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.junit.Test;
  2. //import src.main.java.BasicStatistic;
  3.  
  4. import static org.junit.Assert.*;
  5.  
  6. public class BasicStatisticTest {
  7.  
  8.     @Test
  9.     public void numberOfDataItemsShouldBeZeroWhenNoneItemsWereAdded() {
  10.         // arrange
  11.         BasicStatistic basicStatistic = new BasicStatistic();
  12.  
  13.         // act
  14.         int amountOfItemsInDataList = basicStatistic.numberOfDataItems();
  15.  
  16.         // assert
  17.         assertEquals(0, amountOfItemsInDataList);
  18.     }
  19.  
  20.     @Test
  21.     public void numberOfDataItemsShouldBeMoreThanZeroAfterAdding() {
  22.         // arrange
  23.         BasicStatistic basicStatistic = new BasicStatistic();
  24.  
  25.         // act
  26.         basicStatistic.addDoubleToData(new Double(12));
  27.         int amountOfItemsInDataList = basicStatistic.numberOfDataItems();
  28.  
  29.         // assert
  30.         assertEquals(1, amountOfItemsInDataList);
  31.     }
  32.  
  33.     @Test
  34.     public void clearDataShouldSetDataListToBeEmpty() {
  35.         // arrange
  36.         BasicStatistic basicStatistic = new BasicStatistic();
  37.  
  38.         // act
  39.         basicStatistic.addDoubleToData(new Double(12));
  40.         basicStatistic.addDoubleToData(new Double(13));
  41.         basicStatistic.clearData();;
  42.  
  43.         int amountOfItemsInDataList = basicStatistic.numberOfDataItems();
  44.  
  45.         // assert
  46.         assertEquals(0, amountOfItemsInDataList);
  47.     }
  48.  
  49.     @Test
  50.     public void addingItemsToDataListShouldIncreaseAmountOfItems() {
  51.         // arrange
  52.         BasicStatistic basicStatistic = new BasicStatistic();
  53.  
  54.         // act
  55.         int beforeAddedItemsInDataListCount = 0;
  56.         basicStatistic.addDoubleToData(new Double(11));
  57.         basicStatistic.addDoubleToData(new Double(2));
  58.         basicStatistic.addDoubleToData(new Double(9));
  59.         int afterAddedItemsToDataListCount = basicStatistic.numberOfDataItems();
  60.  
  61.         // assert
  62.         assertEquals(beforeAddedItemsInDataListCount + 3, afterAddedItemsToDataListCount);
  63.     }
  64.  
  65.     @Test
  66.     public void sumShouldReturnTotalSumOfAllItemsInDataList() {
  67.         // arrange
  68.         BasicStatistic basicStatistic = new BasicStatistic();
  69.  
  70.         // act
  71.         basicStatistic.addDoubleToData(new Double(14));
  72.         basicStatistic.addDoubleToData(new Double(22));
  73.         Double sumOfAllItemsInDataList = basicStatistic.sum();
  74.  
  75.         // assert
  76.         assertEquals(36, sumOfAllItemsInDataList.doubleValue(), 0.5);
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top