+/EE422C
software design
git clone https://git.julia.blue/+/EE422C
7e47727
master
1package assignment6 ; 2 3import org .junit .BeforeClass ; 4import org .junit .Test ; 5 6import java .util .HashMap ; 7import java .util .HashSet ; 8import java .util .List ; 9import java .util .Map ; 10 11import static org .junit .Assert .*; 12 13public class A6SampleTest { 14 15private static String show ="A6 Movie" ; 16private static List <Theater .Ticket >concurrencyTestLog ; 17 18private static void joinAllThreads (List <Thread >threads ) 19throws InterruptedException { 20for (Thread t :threads ) { 21t .join (); 22 } 23 } 24 25/** 26* Initialize tests for concurrency by simulating BookingClient with 27* 1) BX1: 100 clients 28* 2) BX2: 100 clients 29* 3) Theater: 100 rows, 2 seats per row 30* <p> 31* Stores the transactions into concurrencyTestLog 32* 33* @throws InterruptedException 34*/ 35@ BeforeClass 36public static void setupBeforeClass ()throws InterruptedException { 37Map <String ,Integer >offices =new HashMap <String ,Integer >() {{ 38put ("BX1" ,100 ); 39put ("BX2" ,100 ); 40 }}; 41 42Theater t =new Theater (100 ,2 ,show ); 43BookingClient bc =new BookingClient (offices ,t ); 44joinAllThreads (bc .simulate ()); 45 46concurrencyTestLog =t .getTransactionLog (); 47 } 48 49/** 50* Tests that bestAvailableSeat() can calculate seats with two letters (ex: AA) 51* <p> 52* Precondition: 30 seats sold 53* Expected: AE1 54* 55* @throws InterruptedException 56*/ 57@ Test (timeout =120000 ) 58public void testBestSeatDouble ()throws InterruptedException { 59Map <String ,Integer >offices =new HashMap <String ,Integer >() {{ 60put ("BX1" ,15 ); 61put ("BX2" ,15 ); 62 }}; 63 64Theater t =new Theater (50 ,1 ,show ); 65BookingClient bc =new BookingClient (offices ,t ); 66joinAllThreads (bc .simulate ()); 67 68Theater .Seat best =t .bestAvailableSeat (); 69assertNotNull (best ); 70assertEquals ("AE1" ,best .toString ()); 71 } 72 73/** 74* Tests that bestAvailableSeat() can handle an empty theater 75* <p> 76* Precondition: Theater has not sold any seats yet 77* Expected: A1 78*/ 79@ Test (timeout =120000 ) 80public void testBestSeatEmpty () { 81Theater t =new Theater (1 ,1 ,show ); 82Theater .Seat best =t .bestAvailableSeat (); 83assertNotNull (best ); 84assertTrue (best .toString ().equalsIgnoreCase ("A1" )); 85 } 86}