Note that there are some explanatory texts on larger screens.

plurals
  1. POgenerate or predict different possible test cases
    primarykey
    data
    text
    <p>I was wishing to know that how am i supposed to know where my program is going wrong.The problem below is an assignment and has to be submitted online.However out of the 10 test cases my solution works for the first 6 .The other four give a <strong>wrong answer</strong> as an output.The test Cases are not given or shown to the participants.So could people tell me how should a generate my own set of test Cases for the problem below to know for which scenarios my code is failing?</p> <p>Description:</p> <pre><code>Given M busy-time slots of N people, You need to print all the available time slots when all the N people can schedule a meeting for a duration of K minutes. Event time will be of form HH MM ( where 0 &lt;= HH &lt;= 23 and 0 &lt;= MM &lt;= 59 ), K will be in the form minutes. Input Format: M K [ M number of busy time slots , K is the duration in minutes ] Followed by M lines with 4 numbers on each line. Each line will be of form StartHH StartMM EndHH EndMM [ Example 9Am-11Am time slot will be given as 9 00 11 00 ] An event time slot is of form [Start Time, End Time ) . Which means it inclusive at start time but doesn’t include the end time. So an event of form 10 00 11 00 =&gt; implies that the meeting start at 10:00 and ends at 11:00, so another meeting can start at 11:00. Sample Input: 5 120 16 00 17 00 10 30 14 30 20 45 22 15 10 00 13 15 09 00 11 00 Sample Output: 00 00 09 00 17 00 20 45 Sample Input: 8 60 08 00 10 15 22 00 23 15 17 00 19 00 07 00 09 45 09 00 13 00 16 00 17 45 12 00 13 30 11 30 12 30 Sample Output: 00 00 07 00 13 30 16 00 19 00 22 00 Constraints : 1 &lt;= M &lt;= 100 Note: 24 00 has to be presented as 00 00. </code></pre> <p>I dont want a solution as i already have one(though not exactly perfect) but just that how should a generate my own set of test cases?I am using Java.My question is related as to how to test my code?</p> <p>My Solution as Requested:-</p> <pre><code>import java.text.NumberFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.StringTokenizer; public class Solution { private static final Scanner scan = new Scanner(System.in); static Map&lt;Integer,Integer&gt; map = new HashMap&lt;Integer,Integer&gt;(); static ArrayList&lt;Integer&gt; stime = new ArrayList&lt;Integer&gt;(); static StringTokenizer str = null; static int limit; static int[] timeArr = new int[1440]; ArrayList&lt;Integer&gt; time = new ArrayList&lt;Integer&gt;(); public static void main(String args[]) { initialize(timeArr); String line = scan.nextLine().toString(); str = new StringTokenizer(line); int trials; trials = Integer.parseInt(str.nextToken().toString()); limit = Integer.parseInt(str.nextToken().toString()); int startHr,startMin,endHr,endMin,startTime,endTime; for(int i=0;i&lt;trials;i++) { line = scan.nextLine().toString(); str = new StringTokenizer(line); startHr = Integer.parseInt(str.nextToken()); startMin = Integer.parseInt(str.nextToken()); startTime = startHr*60 + startMin; endHr = Integer.parseInt(str.nextToken()); endMin = Integer.parseInt(str.nextToken()); if(endHr==00 &amp;&amp; endMin == 00) { endHr = 23; endMin = 60; } endTime = (endHr*60 + endMin); //System.out.println(startHr + ":" + startMin + " to " + endHr + ":" + endMin + " is " + startTime + " to " + endTime); fillSlots(startTime,endTime); } //display(); fillMap(); //display(); limitMap(); toProperTime(); } private static void toProperTime() { // TODO Auto-generated method stub int starthr,startmin,endhr,endmin; for(int i=0;i&lt;stime.size();i++) { starthr = (stime.get(i))/60; startmin = (stime.get(i))%60; if(map.get(stime.get(i))==1439) { endhr = (map.get(stime.get(i)) + 1)%24; endmin = (map.get(stime.get(i)) + 1)%24; } else { endhr = (map.get(stime.get(i)) + 1)/60; endmin = (map.get(stime.get(i)) + 1)%60; } System.out.println(getTime(starthr) + " " + getTime(startmin) + " " + getTime(endhr) + " " + getTime(endmin)); } } private static void fillMap() { // TODO Auto-generated method stub int counter = 0; int endTime ,startTime,currentTime ; boolean loop1 = false; boolean loop2 =false; while(counter&lt;1440) { //System.out.println(counter); currentTime = counter; while((counter&lt;1440)&amp;&amp;timeArr[counter]!=1) { loop1 = true; if((counter==1439) || timeArr[counter] == 1) { endTime = counter; counter++; break; } counter++; } if((loop1==true)&amp;&amp;(loop2==false)) { stime.add(currentTime); map.put(currentTime,counter-1); } while((counter&lt;1440)&amp;&amp;timeArr[counter]!=0) { counter++; } loop1 = false; } } private static void displayMap() { // TODO Auto-generated method stub for(int i=0;i&lt;stime.size();i++) System.out.println(stime.get(i) +" till " + map.get(stime.get(i))); } private static void limitMap() { // TODO Auto-generated method stub for(int i=0;i&lt;stime.size();i++) { if((map.get(stime.get(i)) - stime.get(i)) + 1 &lt; limit) { map.remove(stime.get(i)); stime.remove(i); } } } private static void display() { // TODO Auto-generated method stub for(int i=0;i&lt;timeArr.length;i++) { if((i)%60==0) System.out.println(); System.out.print(timeArr[i]); } } private static void initialize(int[] timeArr) { // TODO Auto-generated method stub for(int i=0;i&lt;timeArr.length;i++) { timeArr[i] = 0; } } private static void fillSlots(int startTime,int endTime) { // TODO Auto-generated method stub for(int i =startTime;i&lt;endTime;i++) { timeArr[i] = 1; } } private static String getTime(int x) { // TODO Auto-generated method stub NumberFormat format=NumberFormat.getInstance(); format.setMaximumIntegerDigits(2); format.setMinimumIntegerDigits(2); return format.format(x).replace(",","") ; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload