package TP2; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Arrays; import java.util.Random; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; /** This class contains testing methods for sorting.
* * @author Dr. Denis Pallez
* http://denispallez.i3s.unice.fr */ public class TrisTestEtudiant { // array containing values to be sorted protected static int[] nombres; // size of the array to be sorted protected static final int SIZE = 10; // array will contain values in [1, MAX_VALUE] protected static final int MAX_VALUE = 10; // Random number generator static Random generator ; /** check whether array numbers is correctly sorted or not */ protected boolean arraySorted(int[] numbers) { for (int i = 0; i < numbers.length - 1; i++) { if (numbers[i] > numbers[i + 1]) { return false; } } return true; } /** initialize an array with random values*/ protected void initRandom() { for (int i = 0; i < nombres.length; i++) { nombres[i] = generator.nextInt(MAX_VALUE); } } /** create an array sorted in the decreasing order*/ protected void initWorst() { for (int i = 0; i < nombres.length; i++) { nombres[i] = MAX_VALUE-i; } } /** init an array with values already sorted*/ protected void initBest() { for (int i = 0; i < nombres.length; i++) { nombres[i] = i; } } /** initialize an array with random values that could appear several times*/ protected void initSameValues() { final int NBVAL_DIFF = nombres.length/2 ; int[] values = new int[NBVAL_DIFF]; for (int i=0;i