The Battle for Wesnoth  1.15.2+dev
test_irdya_date.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2003 - 2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY.
10 
11 See the COPYING file for more details.
12 */
13 
14 #define GETTEXT_DOMAIN "wesnoth-test"
15 
16 #include "utils/irdya_datetime.hpp"
17 #include <boost/test/unit_test.hpp>
18 
19 BOOST_AUTO_TEST_SUITE(test_irdya_datetime)
20 
21 BOOST_AUTO_TEST_CASE(test_irdya_date_parse) {
22  irdya_date BW_423 = irdya_date::read_date(" 423 BW ");
23  irdya_date YW_123 = irdya_date::read_date(" 123 YW ");
24  irdya_date BF_109 = irdya_date::read_date(" 109 BF ");
25  irdya_date AF_928 = irdya_date::read_date(" 928 AF ");
26 
27  BOOST_CHECK_EQUAL(BW_423.get_epoch(), irdya_date::EPOCH::BEFORE_WESNOTH);
28  BOOST_CHECK_EQUAL(BW_423.get_year(), 423);
29  BOOST_CHECK_EQUAL(YW_123.get_epoch(), irdya_date::EPOCH::WESNOTH);
30  BOOST_CHECK_EQUAL(YW_123.get_year(), 123);
31  BOOST_CHECK_EQUAL(BF_109.get_epoch(), irdya_date::EPOCH::BEFORE_FALL);
32  BOOST_CHECK_EQUAL(BF_109.get_year(), 109);
33  BOOST_CHECK_EQUAL(AF_928.get_epoch(), irdya_date::EPOCH::AFTER_FALL);
34  BOOST_CHECK_EQUAL(AF_928.get_year(), 928);
35 }
36 
37 BOOST_AUTO_TEST_CASE(test_irdya_date_equal) {
38  irdya_date first(irdya_date::EPOCH::WESNOTH, 12);
39  irdya_date second(irdya_date::EPOCH::WESNOTH, 12);
40  BOOST_CHECK_EQUAL(first, second);
41 }
42 
43 BOOST_AUTO_TEST_CASE(test_irdya_date_ordering) {
44  irdya_date BW_34(irdya_date::EPOCH::BEFORE_WESNOTH, 34), BW_12(irdya_date::EPOCH::BEFORE_WESNOTH, 12), YW_40(irdya_date::EPOCH::WESNOTH, 40), YW_52(irdya_date::EPOCH::WESNOTH, 52);
45  irdya_date BF_29(irdya_date::EPOCH::BEFORE_FALL, 29), BF_42(irdya_date::EPOCH::BEFORE_FALL, 42), AF_12(irdya_date::EPOCH::AFTER_FALL, 12), AF_102(irdya_date::EPOCH::AFTER_FALL, 102), Y0;
46 
47  std::vector<std::pair<irdya_date, irdya_date>> test_cases {
48  {BW_34, BW_12},
49  {BW_34, YW_40},
50  {BW_34, YW_52},
51  {BW_34, BF_42},
52  {BW_34, BF_29},
53  {BW_34, AF_12},
54  {BW_34, AF_102},
55  {BW_34, Y0},
56 
57  {BW_12, YW_40},
58  {BW_12, YW_52},
59  {BW_12, BF_42},
60  {BW_12, BF_29},
61  {BW_12, AF_12},
62  {BW_12, AF_102},
63  {BW_12, Y0},
64 
65  {YW_40, YW_52},
66  {YW_40, BF_42},
67  {YW_40, BF_29},
68  {YW_40, AF_12},
69  {YW_40, AF_102},
70  {YW_40, Y0},
71 
72  {YW_52, BF_42},
73  {YW_52, BF_29},
74  {YW_52, AF_12},
75  {YW_52, AF_102},
76  {YW_52, Y0},
77 
78  {BF_42, BF_29},
79  {BF_42, AF_12},
80  {BF_42, AF_102},
81  {BF_42, Y0},
82 
83  {BF_29, AF_12},
84  {BF_29, AF_102},
85  {BF_29, Y0},
86 
87  {AF_12, AF_102},
88  {AF_12, Y0},
89  {AF_102, Y0},
90  };
91  for(const auto& pair : test_cases) {
92  BOOST_CHECK(pair.first < pair.second);
93  BOOST_CHECK(!(pair.second < pair.first));
94  }
95 }
96 
97 BOOST_AUTO_TEST_SUITE_END()
static irdya_date read_date(const std::string &date)
unsigned int get_year() const
EPOCH get_epoch() const
BOOST_AUTO_TEST_CASE(test_irdya_date_parse)