Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cinemabooking;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Random;
- /**
- * Used to test your algorithms for selecting seats in a cinema.
- * @author hypesystem
- */
- public final class AlgorithmTest {
- static final int number_of_seats = 5;
- static final Algorithm algorithm = new BookFartAlgorithm();
- private ArrayList<ArrayList<Seat>> seats;
- private ArrayList<Seat> selected;
- private Random rnd;
- private int width, height;
- public AlgorithmTest() {
- seats = new ArrayList<ArrayList<Seat>>();
- selected = new ArrayList<Seat>();
- rnd = new Random(5330);
- width = 0;
- height = 0;
- for(int i = 0; i < 5; i++) runTest();
- }
- public void autoSelectTest() {
- System.out.print("AutoSelectTest: ");
- selected = algorithm.autoSelect(seats, number_of_seats);
- System.out.println(Arrays.deepToString(selected.toArray()));
- }
- public void randomClickTest() {
- System.out.println("RandomClickTest: ");
- int x = rnd.nextInt(width), y = rnd.nextInt(height);
- selected = algorithm.seatClicked(seats, x, y, number_of_seats);
- System.out.println(Arrays.deepToString(selected.toArray()));
- }
- public void setSeats() {
- seats.clear();
- System.out.print("Seats set: ");
- width = rnd.nextInt(15) + 11;
- height = rnd.nextInt(10) + 11;
- for(int i = 0; i < width; i++) {
- seats.add(new ArrayList<Seat>());
- for(int j = 0; j < height; j++) {
- boolean booked = false;
- if(rnd.nextInt(100) < 15) booked = true;
- seats.get(i).add(new Seat(i,j,booked));
- }
- }
- System.out.println(Arrays.deepToString(seats.toArray()));
- }
- public void runTest() {
- setSeats();
- autoSelectTest();
- for(int i = 0; i < 5; i++) randomClickTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment