We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
static Random rand = new Random();
public static class TestDataEmptyArray
{
public static int[] get_array()
{
return new int[0];
}
}
public static class TestDataUniqueValues
{
static int[] arr;
public static int[] get_array()
{
int bound = rand.nextInt(100) + 2;
arr = new int[bound];
Set<Integer> set = new HashSet<>();
while (set.size() < bound)
{
set.add(rand.nextInt(100000));
}
arr = set.stream().mapToInt(Integer::intValue).toArray();
return arr;
}
public static int get_expected_result()
{
int min_index = 0;
for (int i = 1; i < arr.length; i++)
{
if (arr[i] < arr[min_index])
{
min_index = i;
}
}
return min_index;
}
}
public static class TestDataExactlyTwoDifferentMinimums
{
static int[] arr;
public static int[] get_array()
{
int bound = rand.nextInt(100) + 2;
arr = new int[bound];
Set<Integer> set = new HashSet<>();
while (set.size() < bound - 1)
{
set.add(rand.nextInt(100000));
}
arr = set.stream().mapToInt(Integer::intValue).toArray();
Arrays.sort(arr);
arr[arr.length - 1] = arr[0];
return arr;
}
public static int get_expected_result()
{
int min_index = 0;
for (int i = 1; i < arr.length; i++)
{
if (arr[i] < arr[min_index])
{
min_index = i;
}
}
I wanted to go off track and use abstract classes, but everything ended up being more straightforward than I expected, haha.
return min_index;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 27: Testing
You are viewing a single comment's thread. Return to all comments →
JAVA 8
I wanted to go off track and use abstract classes, but everything ended up being more straightforward than I expected, haha.