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 | |
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(testname: "Self equal case" , testcond: threeDays == threeDays); |
21 | check(testname: "Not equal case" , testcond: !(threeDays == twoDays)); |
22 | check(testname: "Less case succeed" , testcond: twoDays < threeDays); |
23 | check(testname: "Not less case" , testcond: !(threeDays < twoDays)); |
24 | check(testname: "Not less case - equal" , testcond: !(threeDays < threeDays)); |
25 | check(testname: "Greater than " , testcond: !(threeDays > threeDays)); |
26 | check(testname: "Greater equal " , testcond: threeDays >= threeDays); |
27 | check(testname: "Greater equal - false" , testcond: !(twoDays >= threeDays)); |
28 | check(testname: "add" , testcond: twoDays + threeDays == date_duration(5)); |
29 | date_duration fiveDays = threeDays; |
30 | fiveDays += twoDays; |
31 | check(testname: "add" , testcond: fiveDays == date_duration(5)); |
32 | date_duration tenDays = fiveDays; |
33 | tenDays += date_duration(5); |
34 | check(testname: "add" , testcond: tenDays.days() == 10); |
35 | |
36 | date_duration derivedOneDay = threeDays - twoDays; |
37 | check(testname: "Subtraction - neg result" , testcond: twoDays - threeDays == date_duration(-1)); |
38 | date_duration oneDay(1); |
39 | check(testname: "Subtraction" , testcond: oneDay == derivedOneDay); |
40 | date_duration fiveDaysDerived = tenDays; |
41 | fiveDaysDerived -= fiveDays; |
42 | check(testname: "Subtraction" , testcond: fiveDaysDerived == fiveDays); |
43 | |
44 | oneDay = twoDays / 2; |
45 | check(testname: "Division" , testcond: oneDay.days() == 1); |
46 | date_duration oneDayDivide = threeDays / 2; |
47 | check(testname: "Division" , testcond: oneDayDivide.days() == 1); |
48 | date_duration hundred(100); |
49 | hundred /= -10; |
50 | check(testname: "Division" , testcond: hundred.days() == -10 && hundred.is_negative()); |
51 | |
52 | date_duration pos_dur(123); |
53 | date_duration neg_dur(-pos_dur); |
54 | check(testname: "unary-" , testcond: 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(testname: "pos_inf + neg_inf" , testcond: (pi_dur + ni_dur) == nd_dur); |
61 | //check("inf * integer", (pi_dur * 2) == pi_dur); // not implemented |
62 | check(testname: "neg_inf / integer" , testcond: (ni_dur / 3) == ni_dur); |
63 | check(testname: "inf + dur" , testcond: (pi_dur + hundred) == pi_dur); |
64 | check(testname: "unary-" , testcond: date_duration(-pi_dur) == ni_dur); |
65 | |
66 | // date_duration dd(1); |
67 | // dd++; |
68 | // check("Increment", dd == twoDays); |
69 | |
70 | } |
71 | |
72 | int main() { |
73 | test_date_duration(); |
74 | return printTestStats(); |
75 | |
76 | } |
77 | |
78 | |