Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.polsl.java.kamil.zietek.lab2.test;
- import java.util.Arrays;
- import pl.polsl.java.kamil.zietek.lab2.model.Lottery;
- import static org.junit.Assert.*;
- import org.junit.*;
- /**
- * Test for class Lottery
- *
- * @author Kamil Zietek
- * @version 2.0
- */
- public class LotteryTest {
- /**
- * instance of Lottery object
- */
- Lottery instance;
- /**
- * Initialization of Lottery object
- */
- @Before
- public void init() {
- instance = new Lottery();
- }
- /**
- * Test of fillResultsWithRandomNumbers method, of class Lottery. Two arrays
- * can't be identical after fillResultsWithRandomNumbers
- */
- @Test
- public void testFillResultsWithRandomNumbersIfAreUnique() {
- Lottery instance2 = new Lottery();
- instance.fillResultsWithRandomNumbers();
- instance2.fillResultsWithRandomNumbers();
- assertFalse("Results of two randomizations are the same!", Arrays.equals(instance.getResults(), instance2.getResults()));
- }
- /**
- * Test of fillResultsWithRandomNumbers method, of class Lottery. Generated
- * array should be sorted
- */
- @Test
- public void testFillResultsWithRandomNumbersIfAreSorted() {
- instance.fillResultsWithRandomNumbers();
- int[] copy = Arrays.copyOf(instance.getResults(), instance.getResults().length);
- Arrays.sort(copy);
- assertArrayEquals("Array after sorting is different than before!", instance.getResults(), copy);//takie same wywala komunikat
- }
- /**
- * Test of fillResultsWithRandomNumbers method, of class Lottery. Array
- * can't contain recurring values
- */
- @Test
- public void testFillResultsWithRandomNumbersIfContainUniqueValues() {
- instance.fillResultsWithRandomNumbers();
- for (int i = 0; i < instance.getResults().length; i++) {
- for (int j = i + 1; j < instance.getResults().length; j++) {
- if (instance.getResults()[i] == instance.getResults()[j]) {
- fail("One of values occurs more than once!");
- }
- }
- }
- }
- /**
- * Test of deleteTicket method, of class Lottery. Results should be array
- * containing only zeroes after calling deleteTicket().
- */
- @Test
- public void testDeleteTicket() {
- instance.deleteTicket();
- int[] tab2 = {0, 0, 0, 0, 0, 0};
- assertArrayEquals("Deleted ticket contains other values than zeroes!", instance.getResults(), tab2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement