hypesystem

[C1] - AlgorithmTest.java

Nov 8th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package cinemabooking;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Random;
  6.  
  7. /**
  8.  * Used to test your algorithms for selecting seats in a cinema.
  9.  * @author hypesystem
  10.  */
  11. public final class AlgorithmTest {
  12.     static final int number_of_seats = 5;
  13.     static final Algorithm algorithm = new BookFartAlgorithm();
  14.     private ArrayList<ArrayList<Seat>> seats;
  15.     private ArrayList<Seat> selected;
  16.     private Random rnd;
  17.     private int width, height;
  18.    
  19.     public AlgorithmTest() {
  20.         seats = new ArrayList<ArrayList<Seat>>();
  21.         selected = new ArrayList<Seat>();
  22.         rnd = new Random(5330);
  23.         width = 0;
  24.         height = 0;
  25.         for(int i = 0; i < 5; i++) runTest();
  26.     }
  27.    
  28.     public void autoSelectTest() {
  29.         System.out.print("AutoSelectTest: ");
  30.         selected = algorithm.autoSelect(seats, number_of_seats);
  31.         System.out.println(Arrays.deepToString(selected.toArray()));
  32.     }
  33.    
  34.     public void randomClickTest() {
  35.         System.out.println("RandomClickTest: ");
  36.         int x = rnd.nextInt(width), y = rnd.nextInt(height);
  37.         selected = algorithm.seatClicked(seats, x, y, number_of_seats);
  38.         System.out.println(Arrays.deepToString(selected.toArray()));
  39.     }
  40.    
  41.     public void setSeats() {
  42.         seats.clear();
  43.         System.out.print("Seats set: ");
  44.         width = rnd.nextInt(15) + 11;
  45.         height = rnd.nextInt(10) + 11;
  46.         for(int i = 0; i < width; i++) {
  47.             seats.add(new ArrayList<Seat>());
  48.             for(int j = 0; j < height; j++) {
  49.                 boolean booked = false;
  50.                 if(rnd.nextInt(100) < 15) booked = true;
  51.                 seats.get(i).add(new Seat(i,j,booked));
  52.             }
  53.         }
  54.         System.out.println(Arrays.deepToString(seats.toArray()));
  55.     }
  56.    
  57.     public void runTest() {
  58.         setSeats();
  59.         autoSelectTest();
  60.         for(int i = 0; i < 5; i++) randomClickTest();
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment