01: import junit.framework.*;
02:
03: /**
04: A class to test the Day class with JUnit.
05: */
06: public class DayTest extends TestCase
07: {
08: /**
09: This test tests the addDays method with positive
10: parameters.
11: */
12: public void testAdd()
13: {
14: for (int i = 1; i <= MAX_DAYS; i = i * INCREMENT)
15: {
16: Day d1 = new Day(1970, 1, 1);
17: Day d2 = d1.addDays(i);
18: assert d2.daysFrom(d1) == i;
19: }
20: }
21:
22: /**
23: This test tests the addDays method with negative
24: parameters.
25: */
26: public void testAddNegative()
27: {
28: for (int i = 1; i <= MAX_DAYS; i = i * INCREMENT)
29: {
30: Day d1 = new Day(1970, 1, 1);
31: Day d2 = d1.addDays(-i);
32: assert d1.daysFrom(d2) == i;
33: }
34: }
35:
36: /**
37: This test tests the daysFrom method.
38: */
39: public void testDaysFrom()
40: {
41: Day d1 = new Day(1970, 1, 1);
42: Day d2 = new Day(2001, 1, 1);
43: int n = d1.daysFrom(d2);
44: Day d3 = d2.addDays(n);
45: assert d1.getYear() == d3.getYear();
46: assert d1.getMonth() == d3.getMonth();
47: assert d1.getDate() == d3.getDate();
48: }
49:
50: /**
51: This test tests arithmetic around the Gregorian
52: calendar change.
53: */
54: public void testGregorianBoundary()
55: {
56: Day d1 = new Day(1580, 1, 1);
57: Day d2 = d1.addDays(MAX_DAYS);
58: Day d3 = d2.addDays(-MAX_DAYS);
59: assert d3.daysFrom(d1) == 0;
60: }
61:
62: private static final int MAX_DAYS = 10000;
63: private static final int INCREMENT = 10;
64: }
65: