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.
public class Solution {
public static void main(String[] args) throws Exception {
TestDataEmptyArray tea=new TestDataEmptyArray();
try
{
if(tea.get_array().length==0)
{
throw new Exception("Cannot get the minimum value index from an empty sequence");
}
}
catch(Exception ex)
{
if(ex.getMessage() == "Cannot get the minimum value index from an empty sequence")
{
//System.out.print("OK");
}
}
TestDataUniqueValues tduv = new TestDataUniqueValues();
var temp=tduv.get_array();
int minidx=0;
for (int i=0; i<temp.length;i++)
{
if(temp[i]<temp[minidx])
{
minidx=i;
}
}
if(minidx == tduv.get_expected_result())
{
//System.out.print("OK");
}
TestDataExactlyTwoDifferentMinimums tdtdm=new TestDataExactlyTwoDifferentMinimums();
temp=tdtdm.get_array();
var res= -1;
int minItem=999999999;
for (int i=0; i<temp.length;i++)
{
if(temp[i]<minItem)
{
minItem=temp[i];
res=i;
}
}
var tres = tdtdm.get_expected_result();
if(tres==res)
{
System.out.print("OK");
}
}
}
class TestDataEmptyArray
{
public int[] get_array()
{
return new int[0];
}
}
class TestDataUniqueValues
{
public int[] get_array()
{
return new int[]{3,2,6,9,6};
}
public int get_expected_result()
{
return 1;
}
}
class TestDataExactlyTwoDifferentMinimums
{
public int[] get_array()
{
return new int[]{3,2,6,9,2,6};
}
public int get_expected_result()
{
return 1;
}
}
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
public class Solution { public static void main(String[] args) throws Exception {
}
class TestDataEmptyArray { public int[] get_array() { return new int[0]; } }
class TestDataUniqueValues { public int[] get_array() { return new int[]{3,2,6,9,6}; }
}
class TestDataExactlyTwoDifferentMinimums { public int[] get_array() { return new int[]{3,2,6,9,2,6}; }
}