1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Pawel Blokus
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <gtest/gtest.h>
25
#include <drizzled/calendar.h>
27
using namespace drizzled;
29
TEST(calendar_julian_day_number_from_gregorian_date_test, CalculationTest)
31
uint32_t year, month, day;
33
year= 2010; month= 4; day= 2;
34
EXPECT_EQ(2455289, julian_day_number_from_gregorian_date(year, month, day));
36
year= 1976; month= 12; day= 21;
37
EXPECT_EQ(2443134, julian_day_number_from_gregorian_date(year, month, day));
39
year= 2050; month= 6; day= 15;
40
EXPECT_EQ(2469973, julian_day_number_from_gregorian_date(year, month, day));
42
year= 1999; month= 12; day= 31;
43
EXPECT_EQ(2451544, julian_day_number_from_gregorian_date(year, month, day));
45
year= 2008; month= 2; day= 29;
46
EXPECT_EQ(2454526, julian_day_number_from_gregorian_date(year, month, day));
49
TEST(calendar_gregorian_date_from_julian_day_number_test, CalculationTest)
52
uint32_t year_out, month_out, day_out;
55
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
56
EXPECT_TRUE((year_out == 2010) && (month_out == 4) && (day_out == 2));
59
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
60
EXPECT_TRUE((year_out == 1976) && (month_out == 12) && (day_out == 21));
63
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
64
EXPECT_TRUE((year_out == 2050) && (month_out == 6) && (day_out == 15));
67
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
68
EXPECT_TRUE((year_out == 1999) && (month_out == 12) && (day_out == 31));
71
gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
72
EXPECT_TRUE((year_out == 2008) && (month_out == 2) && (day_out == 29));
78
TEST(calendar_day_of_week_test, MondayFirst)
80
/* Friday 2010 IV 2 */
81
ASSERT_EQ(4, day_of_week(2455289, false));
84
TEST(calendar_day_of_week_test, SundayFirst)
86
/* Friday 2010 IV 2 */
87
ASSERT_EQ(5, day_of_week(2455289, true));
93
TEST(calendar_in_unix_epoch_range_test, MinOfRange)
95
uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0;
97
ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
100
TEST(calendar_in_unix_epoch_range_test, MaxOfRange)
102
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7;
104
ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
107
TEST(calendar_in_unix_epoch_range_test, OneSecondBeforeMinOfRange)
109
uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59;
111
ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second));
114
TEST(calendar_in_unix_epoch_range_test, OneSecondAfterMaxOfRange)
116
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8;
118
ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second));
121
TEST(calendar_in_unix_epoch_range_test, InsideRange)
123
uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5;
124
EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
126
year= 2010; month= 4; day= 2; hour= 21; minute= 44; second= 0;
127
EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
129
year= 2020; month= 7; day= 13; hour= 16; minute= 56; second= 59;
130
EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
134
int main(int argc, char **argv)
136
::testing::InitGoogleTest(&argc, argv);
137
return RUN_ALL_TESTS();