Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "date.hpp"
- #define BOOST_TEST_MODULE ut_date
- #include <boost/test/auto_unit_test.hpp>
- #include <iostream>
- #include <ctime>
- BOOST_AUTO_TEST_CASE( version ) {
- using namespace std;
- cout << "Date unit test, last build: " << __TIMESTAMP__ << endl;
- }
- BOOST_AUTO_TEST_CASE( test_greg_to_jdn ) {
- BOOST_CHECK( gregorian_to_jdn( bce_to_astro( 4714 ), 11, 24 ) == -0.5 );
- BOOST_CHECK( gregorian_to_jdn( 1858, 11, 16 ) == 2400000-0.5 );
- BOOST_CHECK( gregorian_to_jdn( 2132, 8, 31 ) == 2500000-0.5 );
- }
- BOOST_AUTO_TEST_CASE( default_ctor ) {
- time_t tNow = time(0);
- tm* currentTime = localtime( &tNow );
- gregorian_t gNow( currentTime->tm_year + 1900,
- currentTime->tm_mon + 1,
- currentTime->tm_mday );
- Date now;
- BOOST_CHECK( now.gregorian() == gNow );
- }
- BOOST_AUTO_TEST_CASE( gregorian_ctor ) {
- gregorian_t const g( bce_to_astro( 4714 ), 11, 24 );
- jdn_t const j = -0.5;
- Date zero( year(g), month(g), day(g) );
- BOOST_CHECK( zero.jdn() == j );
- BOOST_CHECK( zero.gregorian() == g );
- }
- BOOST_AUTO_TEST_CASE( equality_operator ) {
- Date const original( 2001,1,1 );
- Date const same( 2001,1,1 );
- Date const different( 2001,1,2);
- BOOST_CHECK( original == same );
- BOOST_CHECK( !(original == different ) );
- BOOST_CHECK( original != different );
- BOOST_CHECK( !(original != same ) );
- }
- BOOST_AUTO_TEST_CASE( day_addition_operator ) {
- Date start(2000,1,1);
- Date later = start + 10;
- BOOST_CHECK( start.jdn() + 10 == later.jdn() );
- }
- BOOST_AUTO_TEST_CASE( week_addition_operator ) {
- Date start(2000,1,1);
- Date later = start + weeks(10);
- BOOST_CHECK( start.jdn() + 70 == later.jdn() );
- }
- BOOST_AUTO_TEST_CASE( year_addition_operator ) {
- Date start(2000,1,1);
- Date later = start + years(10);
- BOOST_CHECK( Date (2010,1,1) == later.jdn() );
- BOOST_CHECK( Date (2003,3,1) + years(1) == Date(2004,3,1) );
- BOOST_CHECK( Date (2004,3,1) + years(1) == Date(2005,3,1) );
- }
Add Comment
Please, Sign In to add comment