<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$
 */
 
  uses(
    'util.profiling.unittest.TestCase',
    'util.DateUtil'
  );

  /**
   * Test Date utility class
   *
   * @see      xp://util.DateUtil
   * @purpose  Unit Test
   */
  class DateUtilTest extends TestCase {
    
    /**
     * Tests the compare method
     *
     * @access  public
     */
    #[@test]
    function comparison() {
      $this->assertTrue(DateUtil::compare(new Date('1977-12-14'), new Date('1980-05-28')) < 0, 'a < b') &&
      $this->assertTrue(DateUtil::compare(new Date('1980-05-28'), new Date('1977-12-14')) > 0, 'a > b') &&
      $this->assertTrue(DateUtil::compare(new Date('1980-05-28'), new Date('1980-05-28')) == 0, 'a == b');
    }

    /**
     * Tests using the compare method as a usort() callback
     *
     * @access  public
     * @see     php://usort
     */
    #[@test]
    function sorting() {
      $list= array(
        new Date('1977-12-14'),
        new Date('2002-02-21'),
        new Date('1980-05-28'),
      );
      
      usort($list, array('DateUtil', 'compare'));
      $this->assertEquals(new Date('1977-12-14'), $list[0], 'offset 0') &&
      $this->assertEquals(new Date('1980-05-28'), $list[1], 'offset 1') &&
      $this->assertEquals(new Date('2002-02-21'), $list[2], 'offset 2');
    }
  }
?>
<commit_msg>- Add tests from net.xp_framework.unittest.DateUtilTest<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$
 */
 
  uses(
    'util.profiling.unittest.TestCase',
    'util.DateUtil'
  );

  /**
   * Test Date utility class
   *
   * @see      xp://util.DateUtil
   * @purpose  Unit Test
   */
  class DateUtilTest extends TestCase {

    /**
     * Test simple add operations on a usual date.
     *
     * @access  public
     */
    #[@test]
    function testSimpleAddition() {
      $date= &new Date(Date::mktime(12, 15, 11, 1, 1, 2000));
      
      $this->assertEquals(
        new Date(Date::mktime(12, 15, 30, 1, 1, 2000)),
        DateUtil::addSeconds($date, 19)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(12, 44, 11, 1, 1, 2000)),
        DateUtil::addMinutes($date, 29)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(13, 15, 11, 1, 1, 2000)),
        DateUtil::addHours($date, 1)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(12, 15, 11, 1, 2, 2000)),
        DateUtil::addDays($date, 1)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(12, 15, 11, 2, 1, 2000)),
        DateUtil::addMonths($date, 1)
      );
    }
    
    /**
     * Test basic add operations with negative values.
     *
     * @access  public
     */
    #[@test]
    function testSimpleSubstraction() {
      $date= &new Date(Date::mktime(12, 15, 11, 1, 1, 2000));
      
      $this->assertEquals(
        new Date(Date::mktime(12, 14, 52, 1, 1, 2000)),
        DateUtil::addSeconds($date, -19)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(11, 46, 11, 1, 1, 2000)),
        DateUtil::addMinutes($date, -29)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(11, 15, 11, 1, 1, 2000)),
        DateUtil::addHours($date, -1)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(12, 15, 11, 12, 31, 1999)),
        DateUtil::addDays($date, -1)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(12, 15, 11, 12, 1, 1999)),
        DateUtil::addMonths($date, -1)
      );
    }
    
    /**
     * Check leap year handling
     *
     * @access  public
     */
    #[@test]
    function testLeapYear() {
      $date= &new Date(Date::mktime(0, 0, 0, 2, 1, 2000));
      
      $this->assertEquals(
        new Date(Date::mktime(0, 0, 0, 3, 1, 2000)),
        DateUtil::addMonths($date, 1)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(0, 0, 0, 3, 2, 2000)),
        DateUtil::addDays($date, 30)
      );
    }
    
    /**
     * Check non-leap year handling
     *
     * @access  public
     */
    #[@test]
    function testNonLeapYear() {
      $date= &new Date(Date::mktime(0, 0, 0, 2, 1, 1999));
      
      $this->assertEquals(
        new Date(Date::mktime(0, 0, 0, 3, 1, 1999)),
        DateUtil::addMonths($date, 1)
      );
      
      $this->assertEquals(
        new Date(Date::mktime(0, 0, 0, 3, 3, 1999)),
        DateUtil::addDays($date, 30)
      );
    }
    
    /**
     * Tests the compare method
     *
     * @access  public
     */
    #[@test]
    function comparison() {
      $this->assertTrue(DateUtil::compare(new Date('1977-12-14'), new Date('1980-05-28')) < 0, 'a < b') &&
      $this->assertTrue(DateUtil::compare(new Date('1980-05-28'), new Date('1977-12-14')) > 0, 'a > b') &&
      $this->assertTrue(DateUtil::compare(new Date('1980-05-28'), new Date('1980-05-28')) == 0, 'a == b');
    }

    /**
     * Tests using the compare method as a usort() callback
     *
     * @access  public
     * @see     php://usort
     */
    #[@test]
    function sorting() {
      $list= array(
        new Date('1977-12-14'),
        new Date('2002-02-21'),
        new Date('1980-05-28'),
      );
      
      usort($list, array('DateUtil', 'compare'));
      $this->assertEquals(new Date('1977-12-14'), $list[0], 'offset 0') &&
      $this->assertEquals(new Date('1980-05-28'), $list[1], 'offset 1') &&
      $this->assertEquals(new Date('2002-02-21'), $list[2], 'offset 2');
    }
  }
?>

{'fraction_non_alphanumeric': 0.18496267977425815, 'fraction_numerical': 0.07846349899872565, 'mean_word_length': 2.0830527497194162, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3018711', 'n_tokens_mistral': 2228, 'n_tokens_neox': 1878, 'n_words': 415}