Guest User

Untitled

a guest
Jan 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "date.hpp"
  3. #define BOOST_TEST_MODULE ut_date
  4. #include <boost/test/auto_unit_test.hpp>
  5. #include <iostream>
  6. #include <ctime>
  7.  
  8. BOOST_AUTO_TEST_CASE( version ) {
  9. using namespace std;
  10. cout << "Date unit test, last build: " << __TIMESTAMP__ << endl;
  11.  
  12. }
  13.  
  14.  
  15. BOOST_AUTO_TEST_CASE( test_greg_to_jdn ) {
  16. BOOST_CHECK( gregorian_to_jdn( bce_to_astro( 4714 ), 11, 24 ) == -0.5 );
  17. BOOST_CHECK( gregorian_to_jdn( 1858, 11, 16 ) == 2400000-0.5 );
  18. BOOST_CHECK( gregorian_to_jdn( 2132, 8, 31 ) == 2500000-0.5 );
  19. }
  20.  
  21.  
  22.  
  23. BOOST_AUTO_TEST_CASE( default_ctor ) {
  24. time_t tNow = time(0);
  25. tm* currentTime = localtime( &tNow );
  26. gregorian_t gNow( currentTime->tm_year + 1900,
  27. currentTime->tm_mon + 1,
  28. currentTime->tm_mday );
  29.  
  30. Date now;
  31. BOOST_CHECK( now.gregorian() == gNow );
  32.  
  33. }
  34.  
  35.  
  36.  
  37. BOOST_AUTO_TEST_CASE( gregorian_ctor ) {
  38. gregorian_t const g( bce_to_astro( 4714 ), 11, 24 );
  39. jdn_t const j = -0.5;
  40.  
  41. Date zero( year(g), month(g), day(g) );
  42. BOOST_CHECK( zero.jdn() == j );
  43. BOOST_CHECK( zero.gregorian() == g );
  44. }
  45.  
  46.  
  47.  
  48. BOOST_AUTO_TEST_CASE( equality_operator ) {
  49. Date const original( 2001,1,1 );
  50. Date const same( 2001,1,1 );
  51. Date const different( 2001,1,2);
  52.  
  53. BOOST_CHECK( original == same );
  54. BOOST_CHECK( !(original == different ) );
  55. BOOST_CHECK( original != different );
  56. BOOST_CHECK( !(original != same ) );
  57.  
  58. }
  59.  
  60. BOOST_AUTO_TEST_CASE( day_addition_operator ) {
  61. Date start(2000,1,1);
  62. Date later = start + 10;
  63.  
  64. BOOST_CHECK( start.jdn() + 10 == later.jdn() );
  65.  
  66. }
  67.  
  68. BOOST_AUTO_TEST_CASE( week_addition_operator ) {
  69. Date start(2000,1,1);
  70. Date later = start + weeks(10);
  71.  
  72. BOOST_CHECK( start.jdn() + 70 == later.jdn() );
  73.  
  74. }
  75.  
  76. BOOST_AUTO_TEST_CASE( year_addition_operator ) {
  77. Date start(2000,1,1);
  78. Date later = start + years(10);
  79.  
  80. BOOST_CHECK( Date (2010,1,1) == later.jdn() );
  81. BOOST_CHECK( Date (2003,3,1) + years(1) == Date(2004,3,1) );
  82. BOOST_CHECK( Date (2004,3,1) + years(1) == Date(2005,3,1) );
  83.  
  84. }
Add Comment
Please, Sign In to add comment