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 NumPatternTest extends TestCase {
- public void test0() {
- assertOutputEquals(new String[] {}, 0);
- }
- public void test1() {
- assertOutputEquals(new String[] {
- "12"},
- 1);
- }
- public void test2() {
- assertOutputEquals(new String[] {
- "112",
- "233"},
- 2);
- }
- public void test5() {
- assertOutputEquals(new String[] {
- "111112",
- "233333",
- "333334",
- "455555",
- "555556"},
- 5);
- }
- public void test6() {
- assertOutputEquals(new String[] {
- "1111112",
- "2333333",
- "3333334",
- "4555555",
- "5555556",
- "6777777"},
- 6);
- }
- public void test8() {
- assertOutputEquals(new String[] {
- "111111112",
- "233333333",
- "333333334",
- "455555555",
- "555555556",
- "677777777",
- "777777778",
- "899999999"},
- 8);
- }
- private static void assertOutputEquals(final String[] expectedOutputLines, final int inputCount) {
- final PrintStream oldSystemOut = System.out;
- final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- final PrintStream printStream = new PrintStream(byteArrayOutputStream);
- System.setOut(printStream);
- try {
- NumPattern.printNumPattern(inputCount);
- } 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());
- }
- }
- import java.util.Scanner;
- public class NumPattern {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- System.out.println("Enter number of rows:: ");
- int num = scn.nextInt();
- printNumPattern(num);
- }
- static void printNumPattern(int num) {
- // Insert your implementation here.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement