1 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
2  * Use, modification and distribution is subject to the
3  * Boost Software License, Version 1.0. (See accompanying
4  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5  * Author: Jeff Garland, Bart Garst
6  */
7 
8 #include "boost/date_time/gregorian/gregorian.hpp"
9 #include "../testfrmwk.hpp"
10 #include <iostream>
11 
12 
test_date_duration()13 void test_date_duration()
14 {
15   using namespace boost::gregorian;
16 
17   date_duration threeDays(3);
18   date_duration twoDays(2);
19   //date_duration zeroDays(0);
20   check("Self equal case",       threeDays == threeDays);
21   check("Not equal case",        !(threeDays == twoDays));
22   check("Less case succeed",     twoDays < threeDays);
23   check("Not less case",         !(threeDays < twoDays));
24   check("Not less case - equal", !(threeDays < threeDays));
25   check("Greater than ",         !(threeDays > threeDays));
26   check("Greater equal ",        threeDays >= threeDays);
27   check("Greater equal - false", !(twoDays >= threeDays));
28   check("add", twoDays + threeDays == date_duration(5));
29   date_duration fiveDays = threeDays;
30   fiveDays += twoDays;
31   check("add", fiveDays == date_duration(5));
32   date_duration tenDays = fiveDays;
33   tenDays += date_duration(5);
34   check("add", tenDays.days() == 10);
35 
36   date_duration derivedOneDay = threeDays - twoDays;
37   check("Subtraction - neg result", twoDays - threeDays == date_duration(-1));
38   date_duration oneDay(1);
39   check("Subtraction",           oneDay == derivedOneDay);
40   date_duration fiveDaysDerived = tenDays;
41   fiveDaysDerived -= fiveDays;
42   check("Subtraction",           fiveDaysDerived == fiveDays);
43 
44   oneDay = twoDays / 2;
45   check("Division",           oneDay.days() == 1);
46   date_duration oneDayDivide = threeDays / 2;
47   check("Division",           oneDayDivide.days() == 1);
48   date_duration hundred(100);
49   hundred /= -10;
50   check("Division",           hundred.days() == -10 && hundred.is_negative());
51 
52   date_duration pos_dur(123);
53   date_duration neg_dur(-pos_dur);
54   check("unary-", neg_dur.days() == -123);
55 
56   // special values tests
57   date_duration pi_dur(pos_infin);
58   date_duration ni_dur(neg_infin);
59   date_duration nd_dur(not_a_date_time);
60   check("pos_inf + neg_inf",  (pi_dur + ni_dur) == nd_dur);
61   //check("inf * integer",    (pi_dur * 2) == pi_dur); // not implemented
62   check("neg_inf / integer",  (ni_dur / 3) == ni_dur);
63   check("inf + dur",          (pi_dur + hundred) == pi_dur);
64   check("unary-",              date_duration(-pi_dur) == ni_dur);
65 
66 //   date_duration dd(1);
67 //   dd++;
68 //   check("Increment",             dd == twoDays);
69 
70 }
71 
main()72 int main() {
73   test_date_duration();
74   return printTestStats();
75 
76 }
77 
78