Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintStream;
- public class SarathKumarMca_SobhanThakur_Test extends TestCase {
- private static final String NL = System.getProperty("line.separator");
- public void test0() throws IOException {
- final String outputLines = call_printNumberTriangle(0);
- assertEquals("", outputLines);
- }
- public void test1() throws IOException {
- final String outputLines = call_printNumberTriangle(1);
- assertEquals(""
- + "1 " + NL
- ,
- outputLines);
- }
- public void test2() throws IOException {
- final String outputLines = call_printNumberTriangle(2);
- assertEquals(""
- + "1 " + NL
- + "3 2 " + NL
- ,
- outputLines);
- }
- public void test4() throws IOException {
- final String outputLines = call_printNumberTriangle(4);
- assertEquals(""
- + "1 " + NL
- + "3 2 " + NL
- + "4 5 6 " + NL
- + "10 9 8 7 " + NL
- ,
- outputLines);
- }
- public void test5() throws IOException {
- final String outputLines = call_printNumberTriangle(5);
- assertEquals(""
- + "1 " + NL
- + "3 2 " + NL
- + "4 5 6 " + NL
- + "10 9 8 7 " + NL
- + "11 12 13 14 15 " + NL
- ,
- outputLines);
- }
- public void test10() throws IOException {
- final String outputLines = call_printNumberTriangle(10);
- assertEquals(""
- + "1 " + NL
- + "3 2 " + NL
- + "4 5 6 " + NL
- + "10 9 8 7 " + NL
- + "11 12 13 14 15 " + NL
- + "21 20 19 18 17 16 " + NL
- + "22 23 24 25 26 27 28 " + NL
- + "36 35 34 33 32 31 30 29 " + NL
- + "37 38 39 40 41 42 43 44 45 " + NL
- + "55 54 53 52 51 50 49 48 47 46 " + NL
- ,
- outputLines);
- }
- /**
- * Call the <code>printNumberTriangle</code> function, and return a <code>String</code> value, of the
- * <code>System.out.println</code> calls of the code.
- */
- private String call_printNumberTriangle(final int numberOfOutputRows) throws IOException {
- final PrintStream oldSystemOut = System.out;
- final OutputStream outputStream = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outputStream));
- try {
- SarathKumarMca_SobhanThakur.printNumberTriangle(numberOfOutputRows);
- } finally {
- System.setOut(oldSystemOut);
- }
- outputStream.flush();
- outputStream.close();
- return outputStream.toString();
- }
- }
Add Comment
Please, Sign In to add comment