Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * After running these tests, the Date class seems quite reliable.
- * Several extremes have been tested (minimums, maximums) for vast
- * intervals. Irregularities (that are supposed to be there) have
- * been tested (days/year in leap years; days in february).
- * However in conclusion, 1000 DKK is a lot of money. And it would
- * be too easy to rob you of them with a bet like this.
- */
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- /**
- * The test class DateTest.
- *
- * @author hypesystem
- */
- public class DateTest
- {
- /**
- * Default constructor for test class DateTest
- */
- public DateTest()
- {
- }
- /**
- * Sets up the test fixture.
- *
- * Called before every test case method.
- */
- @Before
- public void setUp()
- {
- }
- /**
- * Tears down the test fixture.
- *
- * Called after every test case method.
- */
- @After
- public void tearDown()
- {
- }
- @Test
- public void testTue20071002()
- {
- Date newDate = new Date(2007, 10, 02);
- assertEquals(1, newDate.weekDay());
- }
- @Test
- public void test20070101()
- {
- Date newDate20070101 = new Date(2007, 1, 1);
- assertEquals(0, newDate20070101.weekDay());
- assertEquals(1, newDate20070101.weekNumber());
- assertEquals(1, newDate20070101.dayInYear());
- assertEquals(false, newDate20070101.isLeapyear());
- }
- @Test
- public void test20071231()
- {
- Date newDate20071231 = new Date(2007, 12, 31);
- assertEquals(0, newDate20071231.weekDay());
- assertEquals(53, newDate20071231.weekNumber());
- assertEquals(365, newDate20071231.dayInYear());
- assertEquals(false, newDate20071231.isLeapyear());
- }
- @Test
- public void testDaynumbers2007()
- {
- Date testdays20073101 = new Date(2007, 1, 31);
- assertEquals(31, testdays20073101.dayInYear());
- Date testdays20070201 = new Date(2007, 2, 1);
- assertEquals(32, testdays20070201.dayInYear());
- Date testdays20070228 = new Date(2007, 2, 28);
- assertEquals(59, testdays20070228.dayInYear());
- Date testdays20070301 = new Date(2007, 3, 1);
- assertEquals(60, testdays20070301.dayInYear());
- Date testdays20071201 = new Date(2007, 12, 1);
- assertEquals(335, testdays20071201.dayInYear());
- Date testdays20071231 = new Date(2007, 12, 31);
- assertEquals(365, testdays20071231.dayInYear());
- }
- @Test
- public void testYearEnd()
- {
- Date testDateDec;
- Date testDateJan;
- for(int i = 1582; i <= 2500; i++)
- {
- testDateDec = new Date(i, 12, 31);
- testDateJan = new Date(i + 1, 1, 1);
- int days_inbetween = testDateJan.dayNumber() - testDateDec.dayNumber();
- assertEquals(1, days_inbetween);
- }
- }
- @Test
- public void testYearLength()
- {
- Date testDateLast;
- for(int i = 1582; i <= 2500; i++)
- {
- testDateLast = new Date(i, 12, 31);
- if(testDateLast.isLeapyear())
- {
- assertEquals(366, testDateLast.dayInYear());
- }
- else
- {
- assertEquals(365, testDateLast.dayInYear());
- }
- }
- }
- @Test
- public void testFebMar()
- {
- Date testDateFeb;
- Date testDateMar;
- for(int i = 1582; i <= 2500; i++)
- {
- testDateFeb = new Date(i, 2, 28);
- testDateMar = new Date(i, 3, 1);
- if(testDateFeb.isLeapyear())
- {
- assertEquals(2, testDateMar.dayNumber() - testDateFeb.dayNumber());
- assertEquals(2, testDateFeb.daysTill(testDateMar));
- }
- else
- {
- assertEquals(1, testDateMar.dayNumber() - testDateFeb.dayNumber());
- assertEquals(1, testDateFeb.daysTill(testDateMar));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment