Whoops { public static void main(String... args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (reader.ready()) { String firstLine = reader.readLine(); String[] playerNames = firstLine.split(" "); String secondLine = reader.readLine(); int rounds = Integer.parseInt(secondLine); Whoops whoops = new Whoops(); Player firstPlayer = null; Player previousPlayer = null; for (String player : playerNames) { Player newPlayer = whoops.players.get(player); if (newPlayer == null) { newPlayer = new Player(player); } if (firstPlayer == null) { firstPlayer = previousPlayer = newPlayer; } else { previousPlayer.nextPlayer = newPlayer; newPlayer.previousPlayer = previousPlayer; firstPlayer.previousPlayer = newPlayer; newPlayer.nextPlayer = firstPlayer; } previousPlayer = newPlayer; } whoops.play(firstPlayer, rounds); } reader.close(); }  static void main(String... args);  }
@Test public void testExampleIn() throws IOException { System.setIn(new FileInputStream("example.in")); ByteArrayOutputStream output = new ByteArrayOutputStream(); System.setOut(new PrintStream(output)); Whoops.main(); System.setOut(STANDARD_OUT); Scanner scanner = new Scanner(new File("example.out")); String expected = scanner.useDelimiter("\\A").next(); String actual = output.toString(); Assert.assertEquals(expected, actual); scanner.close(); }
@Test public void testSampleIn() throws IOException { System.setIn(new FileInputStream("sample.in")); ByteArrayOutputStream output = new ByteArrayOutputStream(); System.setOut(new PrintStream(output)); Whoops.main(); Scanner scanner = new Scanner(new File("sample.out")); String expected = scanner.useDelimiter("\\A").next(); String actual = output.toString(); Assert.assertEquals(expected, actual); scanner.close(); }
@Test public void testEveryone() throws IOException { String input = "Brigid Michael JR Richard Tim Lyndsey Will"; input += LINE_SEPARATOR; input += 5; System.setIn(new ByteArrayInputStream(input.getBytes())); Whoops.main(); }
@Test public void testSimple() throws IOException { String input = "Will Michael Brigid"; input += LINE_SEPARATOR; input += 2; System.setIn(new ByteArrayInputStream(input.getBytes())); Whoops.main(); }
@Test public void testLong() throws IOException { String input = "Will Brigid Lyndsey Shemp Larry Curly Moe"; input += LINE_SEPARATOR; input += 2; System.setIn(new ByteArrayInputStream(input.getBytes())); Whoops.main(); }
@Test public void testSuperLong() throws IOException { int numberOfRandoms = 100; String input = "Player1"; for (int i = 2; i < numberOfRandoms / 2; i++) { input += " Player" + i; } input += " Tim"; for (int i = numberOfRandoms / 2; i < numberOfRandoms; i++) { input += " Player" + i; } input += LINE_SEPARATOR; input += 1; System.out.println(input); System.setIn(new ByteArrayInputStream(input.getBytes())); Whoops.main(); }