+/EE422C

software design

git clone https://git.julia.blue/+/EE422C

Joseph RyanAdd the rest of the files7e47727

master
2.4 KiB86 linesraw
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
15    private static String show = "A6 Movie";
16    private static List<Theater.Ticket> concurrencyTestLog;
17
18    private static void joinAllThreads(List<Thread> threads)
19            throws InterruptedException {
20        for (Thread t : threads) {
21            t.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
36    public static void setupBeforeClass() throws InterruptedException {
37        Map<String, Integer> offices = new HashMap<String, Integer>() {{
38            put("BX1", 100);
39            put("BX2", 100);
40        }};
41
42        Theater t = new Theater(100, 2, show);
43        BookingClient bc = new BookingClient(offices, t);
44        joinAllThreads(bc.simulate());
45
46        concurrencyTestLog = 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)
58    public void testBestSeatDouble() throws InterruptedException {
59        Map<String, Integer> offices = new HashMap<String, Integer>() {{
60            put("BX1", 15);
61            put("BX2", 15);
62        }};
63
64        Theater t = new Theater(50, 1, show);
65        BookingClient bc = new BookingClient(offices, t);
66        joinAllThreads(bc.simulate());
67
68        Theater.Seat best = t.bestAvailableSeat();
69        assertNotNull(best);
70        assertEquals("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)
80    public void testBestSeatEmpty() {
81        Theater t = new Theater(1, 1, show);
82        Theater.Seat best = t.bestAvailableSeat();
83        assertNotNull(best);
84        assertTrue(best.toString().equalsIgnoreCase("A1"));
85    }
86}