The Battle for Wesnoth  1.19.7+dev
test_irdya_date.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 
23 
24 BOOST_AUTO_TEST_SUITE(test_irdya_datetime)
25 
26 BOOST_AUTO_TEST_CASE(test_irdya_date_parse) {
27  irdya_date BW_423 = irdya_date::read_date(" 423 BW ");
28  irdya_date YW_123 = irdya_date::read_date(" 123 YW ");
29  irdya_date BF_109 = irdya_date::read_date(" 109 BF ");
30  irdya_date AF_928 = irdya_date::read_date(" 928 AF ");
31 
32  BOOST_CHECK_EQUAL(wesnoth_epoch::get_string(BW_423.get_epoch()), wesnoth_epoch::before_wesnoth);
33  BOOST_CHECK_EQUAL(BW_423.get_year(), 423);
34  BOOST_CHECK_EQUAL(wesnoth_epoch::get_string(YW_123.get_epoch()), wesnoth_epoch::wesnoth);
35  BOOST_CHECK_EQUAL(YW_123.get_year(), 123);
36  BOOST_CHECK_EQUAL(wesnoth_epoch::get_string(BF_109.get_epoch()), wesnoth_epoch::before_fall);
37  BOOST_CHECK_EQUAL(BF_109.get_year(), 109);
38  BOOST_CHECK_EQUAL(wesnoth_epoch::get_string(AF_928.get_epoch()), wesnoth_epoch::after_fall);
39  BOOST_CHECK_EQUAL(AF_928.get_year(), 928);
40 }
41 
42 BOOST_AUTO_TEST_CASE(test_irdya_date_equal) {
43  irdya_date first(wesnoth_epoch::type::wesnoth, 12);
44  irdya_date second(wesnoth_epoch::type::wesnoth, 12);
45  BOOST_CHECK_EQUAL(first, second);
46 }
47 
48 BOOST_AUTO_TEST_CASE(test_irdya_date_ordering) {
49  irdya_date BW_34(wesnoth_epoch::type::before_wesnoth, 34), BW_12(wesnoth_epoch::type::before_wesnoth, 12), YW_40(wesnoth_epoch::type::wesnoth, 40), YW_52(wesnoth_epoch::type::wesnoth, 52);
50  irdya_date BF_29(wesnoth_epoch::type::before_fall, 29), BF_42(wesnoth_epoch::type::before_fall, 42), AF_12(wesnoth_epoch::type::after_fall, 12), AF_102(wesnoth_epoch::type::after_fall, 102), Y0;
51 
52  std::vector<std::pair<irdya_date, irdya_date>> test_cases {
53  {BW_34, BW_12},
54  {BW_34, YW_40},
55  {BW_34, YW_52},
56  {BW_34, BF_42},
57  {BW_34, BF_29},
58  {BW_34, AF_12},
59  {BW_34, AF_102},
60  {BW_34, Y0},
61 
62  {BW_12, YW_40},
63  {BW_12, YW_52},
64  {BW_12, BF_42},
65  {BW_12, BF_29},
66  {BW_12, AF_12},
67  {BW_12, AF_102},
68  {BW_12, Y0},
69 
70  {YW_40, YW_52},
71  {YW_40, BF_42},
72  {YW_40, BF_29},
73  {YW_40, AF_12},
74  {YW_40, AF_102},
75  {YW_40, Y0},
76 
77  {YW_52, BF_42},
78  {YW_52, BF_29},
79  {YW_52, AF_12},
80  {YW_52, AF_102},
81  {YW_52, Y0},
82 
83  {BF_42, BF_29},
84  {BF_42, AF_12},
85  {BF_42, AF_102},
86  {BF_42, Y0},
87 
88  {BF_29, AF_12},
89  {BF_29, AF_102},
90  {BF_29, Y0},
91 
92  {AF_12, AF_102},
93  {AF_12, Y0},
94  {AF_102, Y0},
95  };
96  for(const auto& pair : test_cases) {
97  BOOST_CHECK(pair.first < pair.second);
98  BOOST_CHECK(!(pair.second < pair.first));
99  }
100 }
101 
102 BOOST_AUTO_TEST_SUITE_END()
Calendar for handling and comparing dates using the common epoches of the storyline.
unsigned int get_year() const
static irdya_date read_date(const std::string &date)
wesnoth_epoch::type get_epoch() const
string_enums::enum_base< wesnoth_epoch_defines > wesnoth_epoch
The base template for associating string values with enum values.
Definition: enum_base.hpp:33
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46
BOOST_AUTO_TEST_SUITE(filesystem)
BOOST_AUTO_TEST_CASE(test_irdya_date_parse)
utils::irdya_date irdya_date