• + 0 comments

    JAVA 8

    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;
        }
    }