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