Question: /** * This is the test file for SpecialArray Class */ import static org.junit.Assert.*; import org.junit.Test; /** * @author * */ public class SpecialArrayTest {
/** * This is the test file for SpecialArray Class */ import static org.junit.Assert.*; import org.junit.Test; /** * @author * */ public class SpecialArrayTest { @Test public void testtwoIndexes1() { int[] arr = {1, 3, 5, 6}; int target = 8; int[] ret = {1, 2}; assertArrayEquals("twoIndexes function is wrong !", ret, SpecialArray.twoIndexes(arr, target)); } @Test public void testtwoIndexes2() { int[] arr = {1, 3, 4, 6}; int target = 6; int[] ret = {-1, -1}; assertArrayEquals("twoIndexes function is wrong !", ret, SpecialArray.twoIndexes(arr, target)); } @Test public void testPrintOuter1() { int[][] arr = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12},{13,14,15,16}}; String str = "1 2 3 4 8 12 16 15 14 13 9 5"; assertEquals("printSurroundingArray function is wrong !", str, SpecialArray.printSurroundingArray(arr)); } @Test public void testPrintOuter2() { int[][] arr = {{1,2,3}, {4, 5,6}, {7,8,9}}; String str = "1 2 3 6 9 8 7 4"; assertEquals("printSprialArray function is wrong !", str, SpecialArray.printSurroundingArray(arr)); } @Test public void testPrintOuter3() { int[][] arr = {{1,2,3}}; String str = "1 2 3"; assertEquals("printSprialArray function is wrong !", str, SpecialArray.printSurroundingArray(arr)); } @Test public void testPrintOuter4() { int[][] arr = {{1}}; String str = "1"; assertEquals("printSprialArray function is wrong !", str, SpecialArray.printSurroundingArray(arr)); } @Test public void testPrintSpiral1() { int[][] arr = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12},{13,14,15,16}}; String str = "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10"; assertEquals("SpiralArrayPrint function is wrong !", str, SpecialArray.printSprialArray(arr)); } @Test public void testPrintSpiral2() { int[][] arr = {{1,2,3}, {4, 5,6}, {7,8,9}}; String str = "1 2 3 6 9 8 7 4 5"; assertEquals("SpiralArrayPrint function is wrong !", str, SpecialArray.printSprialArray(arr)); } @Test public void testPrintSpiral3() { int[][] arr = {{1,2,3}}; String str = "1 2 3"; assertEquals("printSprialArray function is wrong !", str, SpecialArray.printSprialArray(arr)); } @Test public void testPrintSpiral4() { int[][] arr = {{1}}; String str = "1"; assertEquals("printSprialArray function is wrong !", str, SpecialArray.printSprialArray(arr)); } }
[can you help me to write code for special array class
This is the SpecialArray class which i need help with] public class SpecialArray { /** * This function is to find two different indexes of elements in an 1D sorted array with sum of the two elements equals a given target value. * If found, return the indexes of the two elements as an array (indexes start from 0). If not found, return an array as [-1,-1]. * @param arr - 1D array * @return ret - If found, an 1D array with the two indexes [small_index, large_index]. If not found, ret = [-1,-1] * Assumption: The elements are unique and sorted in ascending order. * Example1: arr = {1 3 5 6}, target = 7 * ret = [0, 3] * * Example2: arr = {1 3 5 6}, target = 10 * ret = [-1, -1] * */ public static int[] twoIndexes(int[] nums, int target) { int[] ret = {-1, -1}; // if no match, return {-1 -1} //TO-DO: Please fill your code here .... return ret; } /** * This function is to print the the outer surrounding elements of 2D n x m array in clock-wise order. * @param arr - 2D array * @return String - the outer surrounding elements of 2D arr in clock-wise order (numbers should be separated by single space) * * Example: 1 2 3 4 * 5 6 7 8 * 9 10 11 12 * * Return: 1 2 3 4 8 12 11 10 9 5 * */ public static String printSurroundingArray(int[][] arr) { String ret = ""; // TO-DO: Please fill your code here ... return ret.trim(); } * This function is to print a 2D n x n square array in Spiral oder * @param arr - 2D array * @return String - the spiral order of arr (numbers should be separated by single space) * Example: 1 2 3 * 4 5 6 * 7 8 9 * * Return: 1 2 3 6 9 8 7 4 5 */ public static String printSprialArray(int[][] arr) { String ret = ""; // TO-DO: Please fill your code here ... return ret.trim(); } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
