// TimeTest4.java
// Tests the to12HourString method of class Time
// for various specific cases including boundary cases.
public class TimeTest4 {
public static void main(String[] args)
{
System.out.println("Test of values within range:\n");
testTime(0, 0, 0);
testTime(1, 59, 0);
testTime(9, 9, 9);
testTime(10, 10, 10);
testTime(11, 59, 59);
testTime(12, 0, 0);
testTime(13, 0, 59);
testTime(23, 59, 59);
ConsoleInput.pause();
testTime(0);
testTime(60);
testTime(43199);
testTime(43200);
testTime(43260);
testTime(86399);
ConsoleInput.pause();
System.out.println("Test of values out of range:\n");
testTime(0, 0, -1);
testTime(0, -1, 0);
testTime(-1, 0, 0);
testTime(23, 59, 60);
testTime(23, 60, 59);
testTime(24, 59, 59);
testTime(-1);
testTime(86400);
} // class main
public static void testTime(int h, int m, int s)
{
try {
Time t = new Time(h, m, s);
System.out.println(t.to12HourString() + " "
+ t + " " + t.getHour() + " hr, "
+ t.getMinute() + " min, "
+ t.getSecond() + " sec, or "
+ t.getTotalSeconds() + " total seconds.");
} catch ( IllegalArgumentException iae ) {
System.out.println(iae.toString());
} // catch
System.out.println(" Was " + h + " hr, " + m + " min, "
+ s + " sec, or " + (3600*h + 60*m + s)
+ " total seconds.");
} // method testTime(int, int, int)
public static void testTime(int totalSeconds)
{
try {
Time t = new Time(totalSeconds);
System.out.println(t.to12HourString() + " "
+ t + " " + t.getHour() + " hr, "
+ t.getMinute() + " min, "
+ t.getSecond() + " sec, or "
+ t.getTotalSeconds() + " total seconds.");
} catch ( IllegalArgumentException iae ) {
System.out.println(iae.toString());
} // catch
int h = totalSeconds / 3600;
int m = totalSeconds / 60 % 60;
int s = totalSeconds % 60;
System.out.println(" Was " + h + " hr, " + m + " min, "
+ s + " sec, or " + (3600*h + 60*m + s)
+ " total seconds.");
} // method testTime(int)
} // class TimeTest4