Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.51 KB | None | 0 0
  1. package pl.polsl.java.kamil.zietek.lab2.test;
  2.  
  3. import java.util.Arrays;
  4. import pl.polsl.java.kamil.zietek.lab2.model.Lottery;
  5. import static org.junit.Assert.*;
  6. import org.junit.*;
  7.  
  8. /**
  9.  * Test for class Lottery
  10.  *
  11.  * @author Kamil Zietek
  12.  * @version 2.0
  13.  */
  14. public class LotteryTest {
  15.  
  16.     /**
  17.      * instance of Lottery object
  18.      */
  19.     Lottery instance;
  20.  
  21.     /**
  22.      * Initialization of Lottery object
  23.      */
  24.     @Before
  25.     public void init() {
  26.         instance = new Lottery();
  27.     }
  28.  
  29.     /**
  30.      * Test of fillResultsWithRandomNumbers method, of class Lottery. Two arrays
  31.      * can't be identical after fillResultsWithRandomNumbers
  32.      */
  33.     @Test
  34.     public void testFillResultsWithRandomNumbersIfAreUnique() {
  35.         Lottery instance2 = new Lottery();
  36.         instance.fillResultsWithRandomNumbers();
  37.         instance2.fillResultsWithRandomNumbers();
  38.         assertFalse("Results of two randomizations are the same!", Arrays.equals(instance.getResults(), instance2.getResults()));
  39.     }
  40.  
  41.     /**
  42.      * Test of fillResultsWithRandomNumbers method, of class Lottery. Generated
  43.      * array should be sorted
  44.      */
  45.     @Test
  46.     public void testFillResultsWithRandomNumbersIfAreSorted() {
  47.         instance.fillResultsWithRandomNumbers();
  48.         int[] copy = Arrays.copyOf(instance.getResults(), instance.getResults().length);
  49.         Arrays.sort(copy);
  50.         assertArrayEquals("Array after sorting is different than before!", instance.getResults(), copy);//takie same wywala komunikat
  51.     }
  52.  
  53.     /**
  54.      * Test of fillResultsWithRandomNumbers method, of class Lottery. Array
  55.      * can't contain recurring values
  56.      */
  57.     @Test
  58.     public void testFillResultsWithRandomNumbersIfContainUniqueValues() {
  59.         instance.fillResultsWithRandomNumbers();
  60.         for (int i = 0; i < instance.getResults().length; i++) {
  61.             for (int j = i + 1; j < instance.getResults().length; j++) {
  62.                 if (instance.getResults()[i] == instance.getResults()[j]) {
  63.                     fail("One of values occurs more than once!");
  64.                 }
  65.             }
  66.         }
  67.     }
  68.  
  69.     /**
  70.      * Test of deleteTicket method, of class Lottery. Results should be array
  71.      * containing only zeroes after calling deleteTicket().
  72.      */
  73.     @Test
  74.     public void testDeleteTicket() {
  75.         instance.deleteTicket();
  76.         int[] tab2 = {0, 0, 0, 0, 0, 0};
  77.         assertArrayEquals("Deleted ticket contains other values than zeroes!", instance.getResults(), tab2);
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement