hypesystem

GB.1

Sep 29th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. /**
  2.  *  After running these tests, the Date class seems quite reliable.
  3.  *  Several extremes have been tested (minimums, maximums) for vast
  4.  *  intervals. Irregularities (that are supposed to be there) have
  5.  *  been tested (days/year in leap years; days in february).
  6.  *  However in conclusion, 1000 DKK is a lot of money. And it would
  7.  *  be too easy to rob you of them with a bet like this.
  8.  */
  9.  
  10. import static org.junit.Assert.*;
  11. import org.junit.After;
  12. import org.junit.Before;
  13. import org.junit.Test;
  14.  
  15. /**
  16.  * The test class DateTest.
  17.  *
  18.  * @author  hypesystem
  19.  */
  20. public class DateTest
  21. {
  22.     /**
  23.      * Default constructor for test class DateTest
  24.      */
  25.     public DateTest()
  26.     {
  27.     }
  28.  
  29.     /**
  30.      * Sets up the test fixture.
  31.      *
  32.      * Called before every test case method.
  33.      */
  34.     @Before
  35.     public void setUp()
  36.     {
  37.     }
  38.  
  39.     /**
  40.      * Tears down the test fixture.
  41.      *
  42.      * Called after every test case method.
  43.      */
  44.     @After
  45.     public void tearDown()
  46.     {
  47.     }
  48.  
  49.     @Test
  50.     public void testTue20071002()
  51.     {
  52.         Date newDate = new Date(2007, 10, 02);
  53.         assertEquals(1, newDate.weekDay());
  54.     }
  55.  
  56.  
  57.     @Test
  58.     public void test20070101()
  59.     {
  60.         Date newDate20070101 = new Date(2007, 1, 1);
  61.         assertEquals(0, newDate20070101.weekDay());
  62.         assertEquals(1, newDate20070101.weekNumber());
  63.         assertEquals(1, newDate20070101.dayInYear());
  64.         assertEquals(false, newDate20070101.isLeapyear());
  65.     }
  66.  
  67.     @Test
  68.     public void test20071231()
  69.     {
  70.         Date newDate20071231 = new Date(2007, 12, 31);
  71.         assertEquals(0, newDate20071231.weekDay());
  72.         assertEquals(53, newDate20071231.weekNumber());
  73.         assertEquals(365, newDate20071231.dayInYear());
  74.         assertEquals(false, newDate20071231.isLeapyear());
  75.     }
  76.    
  77.     @Test
  78.     public void testDaynumbers2007()
  79.     {
  80.         Date testdays20073101 = new Date(2007, 1, 31);
  81.         assertEquals(31, testdays20073101.dayInYear());
  82.         Date testdays20070201 = new Date(2007, 2, 1);
  83.         assertEquals(32, testdays20070201.dayInYear());
  84.         Date testdays20070228 = new Date(2007, 2, 28);
  85.         assertEquals(59, testdays20070228.dayInYear());
  86.         Date testdays20070301 = new Date(2007, 3, 1);
  87.         assertEquals(60, testdays20070301.dayInYear());
  88.         Date testdays20071201 = new Date(2007, 12, 1);
  89.         assertEquals(335, testdays20071201.dayInYear());
  90.         Date testdays20071231 = new Date(2007, 12, 31);
  91.         assertEquals(365, testdays20071231.dayInYear());
  92.     }
  93.    
  94.     @Test
  95.     public void testYearEnd()
  96.     {
  97.         Date testDateDec;
  98.         Date testDateJan;
  99.        
  100.         for(int i = 1582; i <= 2500; i++)
  101.         {
  102.             testDateDec = new Date(i, 12, 31);
  103.             testDateJan = new Date(i + 1, 1, 1);
  104.             int days_inbetween = testDateJan.dayNumber() - testDateDec.dayNumber();
  105.             assertEquals(1, days_inbetween);
  106.         }
  107.     }
  108.    
  109.     @Test
  110.     public void testYearLength()
  111.     {
  112.         Date testDateLast;
  113.        
  114.         for(int i = 1582; i <= 2500; i++)
  115.         {
  116.             testDateLast = new Date(i, 12, 31);
  117.             if(testDateLast.isLeapyear())
  118.             {
  119.                 assertEquals(366, testDateLast.dayInYear());
  120.             }
  121.             else
  122.             {
  123.                 assertEquals(365, testDateLast.dayInYear());
  124.             }
  125.         }
  126.     }
  127.    
  128.     @Test
  129.     public void testFebMar()
  130.     {
  131.         Date testDateFeb;
  132.         Date testDateMar;
  133.        
  134.         for(int i = 1582; i <= 2500; i++)
  135.         {
  136.             testDateFeb = new Date(i, 2, 28);
  137.             testDateMar = new Date(i, 3, 1);
  138.             if(testDateFeb.isLeapyear())
  139.             {
  140.                 assertEquals(2, testDateMar.dayNumber() - testDateFeb.dayNumber());
  141.                 assertEquals(2, testDateFeb.daysTill(testDateMar));
  142.             }
  143.             else
  144.             {
  145.                 assertEquals(1, testDateMar.dayNumber() - testDateFeb.dayNumber());
  146.                 assertEquals(1, testDateFeb.daysTill(testDateMar));
  147.             }
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment