Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- import java.io.ByteArrayOutputStream;
- import java.io.PrintStream;
- public class CrossingStarsTest extends TestCase {
- private static void printCrossingStars(final int n) {
- // Your implementation here.
- }
- public void test0() {
- assertOutputEquals(new String[] {
- }, 0);
- }
- public void test1() {
- assertOutputEquals(new String[] {
- " *",
- "**",
- " *",
- }, 1);
- }
- public void test2() {
- assertOutputEquals(new String[] {
- " *",
- " * *",
- "*****",
- " * *",
- " *",
- }, 2);
- }
- public void test3() {
- assertOutputEquals(new String[] {
- " *",
- " * *",
- " * * *",
- "*********",
- " * * *",
- " * *",
- " *",
- }, 3);
- }
- public void test4() {
- assertOutputEquals(new String[] {
- " *",
- " * *",
- " * * *",
- " * * * *",
- "**************",
- " * * * *",
- " * * *",
- " * *",
- " *",
- }, 4);
- }
- public void test5() {
- assertOutputEquals(new String[] {
- " *",
- " * *",
- " * * *",
- " * * * *",
- " * * * * *",
- "********************",
- " * * * * *",
- " * * * *",
- " * * *",
- " * *",
- " *",
- }, 5);
- }
- private static void assertOutputEquals(final String[] expectedOutputLines, final int n) {
- final PrintStream oldSystemOut = System.out;
- final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- final PrintStream printStream = new PrintStream(byteArrayOutputStream);
- System.setOut(printStream);
- try {
- printCrossingStars(n);
- } finally {
- System.setOut(oldSystemOut);
- printStream.close();
- }
- final StringBuilder expectedOutputStringBuilder = new StringBuilder();
- for (final String line : expectedOutputLines) {
- expectedOutputStringBuilder.append(line).append(System.lineSeparator());
- }
- assertEquals(expectedOutputStringBuilder.toString(), byteArrayOutputStream.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement