Create Print2DArraysTest.java

This commit is contained in:
Neetika23 2023-11-24 00:31:59 +05:30 committed by GitHub
parent d64976dff4
commit 990a4812dc
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package com.baeldung.print2DArrays;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ArrayPrinterTest {
@Test
public void testPrint2DNested() {
int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n";
assertEquals(expectedOutput, ArrayPrinter.print2DNested(myArray));
}
@Test
public void testPrint2DStream() {
int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
String expectedOutput = "1 2 3 4 5 6 7 8 9 ";
assertEquals(expectedOutput, ArrayPrinter.print2DStream(myArray));
}
@Test
public void testPrint2DDeepToString() {
int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n";
assertEquals(expectedOutput, ArrayPrinter.print2DDeepToString(myArray));
}
@Test
public void testPrintArrayString() {
int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n";
assertEquals(expectedOutput, ArrayPrinter.printArrayString(myArray));
}
}