diff --git a/test/date_test/day.pass.cpp b/test/date_test/day.pass.cpp index 1a45449..5533c58 100644 --- a/test/date_test/day.pass.cpp +++ b/test/date_test/day.pass.cpp @@ -85,10 +85,10 @@ int main() { using namespace date; - static_assert(std::is_same{}, ""); + static_assert(std::is_same{}, ""); - static_assert(1_d == date::day{1}, ""); - static_assert(2_d == date::day{2}, ""); + static_assert(1_d == day{1}, ""); + static_assert(2_d == day{2}, ""); static_assert( 1_d == 1_d, ""); static_assert(!(1_d == 2_d), ""); diff --git a/test/date_test/daysmweekday.fail.cpp b/test/date_test/daysmweekday.fail.cpp new file mode 100644 index 0000000..45e1afb --- /dev/null +++ b/test/date_test/daysmweekday.fail.cpp @@ -0,0 +1,32 @@ +// The MIT License (MIT) +// +// Copyright (c) 2015 Howard Hinnant +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// days - weekday not allowed + +#include "date.h" + +int +main() +{ + using namespace date; + auto b = days{1} - sun; +} diff --git a/test/date_test/month.pass.cpp b/test/date_test/month.pass.cpp index d4e59a2..1ce054c 100644 --- a/test/date_test/month.pass.cpp +++ b/test/date_test/month.pass.cpp @@ -104,18 +104,18 @@ main() { using namespace date; - static_assert(jan == date::month{1}, ""); - static_assert(feb == date::month{2}, ""); - static_assert(mar == date::month{3}, ""); - static_assert(apr == date::month{4}, ""); - static_assert(may == date::month{5}, ""); - static_assert(jun == date::month{6}, ""); - static_assert(jul == date::month{7}, ""); - static_assert(aug == date::month{8}, ""); - static_assert(sep == date::month{9}, ""); - static_assert(oct == date::month{10}, ""); - static_assert(nov == date::month{11}, ""); - static_assert(dec == date::month{12}, ""); + static_assert(jan == month{1}, ""); + static_assert(feb == month{2}, ""); + static_assert(mar == month{3}, ""); + static_assert(apr == month{4}, ""); + static_assert(may == month{5}, ""); + static_assert(jun == month{6}, ""); + static_assert(jul == month{7}, ""); + static_assert(aug == month{8}, ""); + static_assert(sep == month{9}, ""); + static_assert(oct == month{10}, ""); + static_assert(nov == month{11}, ""); + static_assert(dec == month{12}, ""); static_assert(!(jan != jan), ""); static_assert( jan != feb, ""); diff --git a/test/date_test/weekday.pass.cpp b/test/date_test/weekday.pass.cpp new file mode 100644 index 0000000..eadadc8 --- /dev/null +++ b/test/date_test/weekday.pass.cpp @@ -0,0 +1,202 @@ +// The MIT License (MIT) +// +// Copyright (c) 2015 Howard Hinnant +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// class weekday +// { +// unsigned char wd_; +// public: +// explicit constexpr weekday(unsigned wd) noexcept; +// constexpr weekday(const day_point& dp) noexcept; +// +// weekday& operator++() noexcept; +// weekday operator++(int) noexcept; +// weekday& operator--() noexcept; +// weekday operator--(int) noexcept; +// +// weekday& operator+=(const days& d) noexcept; +// weekday& operator-=(const days& d) noexcept; +// +// constexpr explicit operator unsigned() const noexcept; +// constexpr bool ok() const noexcept; +// +// // tested with weekday_indexed +// constexpr weekday_indexed operator[](unsigned index) const noexcept; +// // tested with weekday_last +// constexpr weekday_last operator[](last_spec) const noexcept; +// }; + +// constexpr bool operator==(const weekday& x, const weekday& y) noexcept; +// constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; + +// constexpr weekday operator+(const weekday& x, const days& y) noexcept; +// constexpr weekday operator+(const days& x, const weekday& y) noexcept; +// constexpr weekday operator-(const weekday& x, const days& y) noexcept; +// constexpr days operator-(const weekday& x, const weekday& y) noexcept; + +// std::ostream& operator<<(std::ostream& os, const weekday& wd); + +// constexpr weekday sun{0}; +// constexpr weekday mon{1}; +// constexpr weekday tue{2}; +// constexpr weekday wed{3}; +// constexpr weekday thu{4}; +// constexpr weekday fri{5}; +// constexpr weekday sat{6}; + +#include "date.h" + +#include +#include +#include + +static_assert( std::is_trivially_destructible{}, ""); +static_assert(!std::is_default_constructible{}, ""); +static_assert( std::is_trivially_copy_constructible{}, ""); +static_assert( std::is_trivially_copy_assignable{}, ""); +static_assert( std::is_trivially_move_constructible{}, ""); +static_assert( std::is_trivially_move_assignable{}, ""); + +static_assert( std::is_nothrow_constructible{}, ""); +static_assert( std::is_nothrow_constructible{}, ""); +static_assert( std::is_nothrow_constructible{}, ""); +static_assert(!std::is_convertible{}, ""); +static_assert( std::is_convertible{}, ""); +static_assert(!std::is_convertible{}, ""); +static_assert(static_cast(date::weekday{1}) == 1, ""); + +static_assert( date::weekday{0}.ok(), ""); +static_assert( date::weekday{1}.ok(), ""); +static_assert( date::weekday{2}.ok(), ""); +static_assert( date::weekday{3}.ok(), ""); +static_assert( date::weekday{4}.ok(), ""); +static_assert( date::weekday{5}.ok(), ""); +static_assert( date::weekday{6}.ok(), ""); +static_assert(!date::weekday{7}.ok(), ""); + +void +test_weekday_arithmetic() +{ + using namespace date; + constexpr unsigned a[7][7] = + {// - Sun Mon Tue Wed Thu Fri Sat + /*Sun*/ {0, 6, 5, 4, 3, 2, 1}, + /*Mon*/ {1, 0, 6, 5, 4, 3, 2}, + /*Tue*/ {2, 1, 0, 6, 5, 4, 3}, + /*Wed*/ {3, 2, 1, 0, 6, 5, 4}, + /*Thu*/ {4, 3, 2, 1, 0, 6, 5}, + /*Fri*/ {5, 4, 3, 2, 1, 0, 6}, + /*Sat*/ {6, 5, 4, 3, 2, 1, 0} + }; + for (unsigned x = 0; x < 7; ++x) + { + for (unsigned y = 0; y < 7; ++y) + { + assert(weekday{x} - weekday{y} == days{a[x][y]}); + assert(weekday{x} - days{a[x][y]} == weekday{y}); + assert(weekday{x} == weekday{y} + days{a[x][y]}); + assert(weekday{x} == days{a[x][y]} + weekday{y}); + } + } + for (unsigned x = 0; x < 7; ++x) + { + for (int y = -21; y < 21; ++y) + { + weekday wx{x}; + days dy{y}; + wx += dy; + weekday wz = weekday{x} + days{y}; + assert(wx.ok()); + assert(wz.ok()); + assert(wx == wz); + assert(wx - weekday{x} == days{y % 7 + (y % 7 < 0 ? 7 : 0)}); + } + } + for (unsigned x = 0; x < 7; ++x) + { + for (int y = -21; y < 21; ++y) + { + weekday wx{x}; + days dy{y}; + wx -= dy; + assert(wx == weekday{x} + days{-y}); + } + } + for (unsigned x = 0; x < 7; ++x) + { + weekday wx{x}; + assert(++wx - weekday{x} == days{1}); + assert(wx++ - weekday{x} == days{1}); + assert(wx - weekday{x} == days{2}); + assert(wx-- - weekday{x} == days{2}); + assert(wx - weekday{x} == days{1}); + assert(--wx - weekday{x} == days{0}); + } +} + +int +main() +{ + using namespace date; + + static_assert(sun == weekday{0}, ""); + static_assert(mon == weekday{1}, ""); + static_assert(tue == weekday{2}, ""); + static_assert(wed == weekday{3}, ""); + static_assert(thu == weekday{4}, ""); + static_assert(fri == weekday{5}, ""); + static_assert(sat == weekday{6}, ""); + + static_assert(!(sun != sun), ""); + static_assert( sun != mon, ""); + static_assert( mon != sun, ""); + + test_weekday_arithmetic(); + + std::ostringstream os; + + os << sun; + assert(os.str() == "Sun"); + os.str(""); + + os << mon; + assert(os.str() == "Mon"); + os.str(""); + + os << tue; + assert(os.str() == "Tue"); + os.str(""); + + os << wed; + assert(os.str() == "Wed"); + os.str(""); + + os << thu; + assert(os.str() == "Thu"); + os.str(""); + + os << fri; + assert(os.str() == "Fri"); + os.str(""); + + os << sat; + assert(os.str() == "Sat"); +} diff --git a/test/date_test/weekday_lessthan.fail.cpp b/test/date_test/weekday_lessthan.fail.cpp new file mode 100644 index 0000000..7f8248d --- /dev/null +++ b/test/date_test/weekday_lessthan.fail.cpp @@ -0,0 +1,32 @@ +// The MIT License (MIT) +// +// Copyright (c) 2015 Howard Hinnant +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// weekday < weekday not allowed + +#include "date.h" + +int +main() +{ + using namespace date; + auto b = sun < mon; +} diff --git a/test/date_test/weekday_sum.fail.cpp b/test/date_test/weekday_sum.fail.cpp new file mode 100644 index 0000000..b6a2b3c --- /dev/null +++ b/test/date_test/weekday_sum.fail.cpp @@ -0,0 +1,32 @@ +// The MIT License (MIT) +// +// Copyright (c) 2015 Howard Hinnant +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// weekday + weekday not allowed + +#include "date.h" + +int +main() +{ + using namespace date; + auto b = sun + mon; +}