Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week2;
- import org.junit.Assert;
- import org.junit.Test;
- import java.io.*;
- /**
- * Created by Benedikt on 27.10.2016.
- */
- public class ATest {
- private static final InputStream sIn = System.in;
- public static final PrintStream sOut = System.out;
- static String inputOutput(String input){
- try {
- InputStream inputStream = new ByteArrayInputStream(input.getBytes("UTF-8"));
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outputStream));
- System.setIn(inputStream);
- A.main(new String[1]);
- System.out.flush();
- System.setIn(sIn);
- System.setOut(sOut);
- return outputStream.toString("UTF-8").trim();
- } catch (Exception e) {
- e.printStackTrace();
- } return "";
- }
- @Test
- public void noCandidates() throws IOException {
- String input = "1\n" +
- "1 0 0\n\n";
- String shouldOutput = "Case #1: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void alreadyMarried() throws IOException {
- String input = "1\n" +
- "2 0 1\n" +
- "1\n" +
- "1 2\n\n";
- String shouldOutput = "Case #1: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void onlyRelated() throws IOException {
- String input = "1\n" +
- "2 1 0\n" +
- "1\n" +
- "1 2\n\n";
- String shouldOutput = "Case #1: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void transitivelyRelated() throws IOException {
- String input = "1\n" +
- "3 2 0\n" +
- "1 2\n" +
- "2 3\n" +
- "1 2\n\n";
- String shouldOutput = "Case #1: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void transitivelyRelatedThroughMarriage() throws IOException {
- String input = "1\n" +
- "3 1 1\n" +
- "1 2\n" +
- "2 3\n" +
- "1 2\n\n";
- String shouldOutput = "Case #1: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void oneCandidate() throws IOException {
- String input = "1\n" +
- "2 0 0\n" +
- "1\n";
- String shouldOutput = "Case #1: 1\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void twoImpossibles() throws IOException {
- String input = "2\n" +
- "2 0 1\n" +
- "1\n" +
- "1 2\n\n" +
- "2 0 1\n" +
- "1\n" +
- "1 2\n\n";
- String shouldOutput = "Case #1: impossible\nCase #2: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void fourImpossibles() throws IOException {
- String input = "4\n" +
- "2 0 1\n" +
- "1\n" +
- "1 2\n\n" +
- "1 0 0\n\n\n" +
- "2 0 1\n" +
- "1\n" +
- "1 2\n\n" +
- "1 0 0\n\n\n";
- String shouldOutput = "Case #1: impossible\nCase #2: impossible\nCase #3: impossible\nCase #4: impossible\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- @Test
- public void mixPossibleImpossible() throws IOException {
- String input = "4\n" +
- "2 0 1\n" +
- "1\n" +
- "1 2\n\n" +
- "5 4 0\n" +
- "619991 362808 274506 846462\n" +
- "3 2\n" +
- "3 2\n" +
- "4 1\n" +
- "2 5\n\n" +
- "1 0 0\n\n\n" +
- "7 2 1\n" +
- "1 2 3 6 4 5\n" +
- "6 7\n" +
- "5 4\n" +
- "4 6\n\n";
- String shouldOutput = "Case #1: impossible\nCase #2: 846462\nCase #3: impossible\nCase #4: 3\n";
- Assert.assertEquals(shouldOutput.trim(), inputOutput(input));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement