import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class ScheduleTester
{
    @Test
    public void testGetColumnWithFewestAgainstExamples()
    {
        Schedule s = new Schedule();
        s.sched = new Appointment[6][5];
        s.sched[0][3] = new Appointment("busy", 206);
        s.sched[0][4] = new Appointment("busy", 204);
        s.sched[1][2] = new Appointment("busy", 304);
        s.sched[1][3] = new Appointment("busy", 206);
        s.sched[1][4] = new Appointment("busy", 202);
        s.sched[2][0] = new Appointment("hold", 201);
        s.sched[2][1] = new Appointment("busy", 105);
        s.sched[2][2] = new Appointment("busy", 205);
        s.sched[2][4] = new Appointment("busy", 205);
        s.sched[3][0] = new Appointment("busy", 204);
        s.sched[3][2] = new Appointment("busy", 310);
        s.sched[3][3] = new Appointment("hold", 110);
        s.sched[4][0] = new Appointment("busy", 204);
        s.sched[4][1] = new Appointment("hold", 201);
        s.sched[4][2] = new Appointment("hold", 310);
        s.sched[4][3] = new Appointment("busy", 105);
        s.sched[5][0] = new Appointment("busy", 105);
        s.sched[5][1] = new Appointment("busy", 208);
        s.sched[5][2] = new Appointment("hold", 310);
        s.sched[5][3] = new Appointment("busy", 105);
        fillNullsWithFree(s.sched);
        
        assertEquals(1, s.columnWithFewest("busy"));
        
        int result = s.columnWithFewest("free");
        assertTrue(result == 2 || result == 3);
        
        assertEquals(4, s.columnWithFewest("hold"));
    }
    
    private static void fillNullsWithFree(Appointment[][] s)
    {
        for(Appointment[] row : s)
            for(int c = 0; c < row.length; c++)
                if(row[c] == null)
                    row[c] = new Appointment("free", 100);
    }
}
