~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/calendar_test.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
#define BOOST_TEST_DYN_LINK
23
 
#include <boost/test/unit_test.hpp>
 
22
 
 
23
#include <gtest/gtest.h>
24
24
 
25
25
#include <drizzled/calendar.h>
26
26
 
27
27
using namespace drizzled;
28
 
BOOST_AUTO_TEST_SUITE(CalculationTest)
29
 
BOOST_AUTO_TEST_CASE(calendar_julian_day_number_from_gregorian_date_test)
 
28
 
 
29
TEST(calendar_julian_day_number_from_gregorian_date_test, CalculationTest)
30
30
{
31
31
  uint32_t year, month, day;
32
32
 
33
33
  year= 2010; month= 4; day= 2;
34
 
  BOOST_REQUIRE_EQUAL(2455289, julian_day_number_from_gregorian_date(year, month, day));
 
34
  EXPECT_EQ(2455289, julian_day_number_from_gregorian_date(year, month, day));
35
35
  
36
36
  year= 1976; month= 12; day= 21;
37
 
  BOOST_REQUIRE_EQUAL(2443134, julian_day_number_from_gregorian_date(year, month, day));
 
37
  EXPECT_EQ(2443134, julian_day_number_from_gregorian_date(year, month, day));
38
38
  
39
39
  year= 2050; month= 6; day= 15;
40
 
  BOOST_REQUIRE_EQUAL(2469973, julian_day_number_from_gregorian_date(year, month, day));
 
40
  EXPECT_EQ(2469973, julian_day_number_from_gregorian_date(year, month, day));
41
41
  
42
42
  year= 1999; month= 12; day= 31;
43
 
  BOOST_REQUIRE_EQUAL(2451544, julian_day_number_from_gregorian_date(year, month, day));
 
43
  EXPECT_EQ(2451544, julian_day_number_from_gregorian_date(year, month, day));
44
44
  
45
45
  year= 2008; month= 2; day= 29;
46
 
  BOOST_REQUIRE_EQUAL(2454526, julian_day_number_from_gregorian_date(year, month, day));
 
46
  EXPECT_EQ(2454526, julian_day_number_from_gregorian_date(year, month, day));
47
47
}
48
48
 
49
 
BOOST_AUTO_TEST_CASE(calendar_gregorian_date_from_julian_day_number_test)
 
49
TEST(calendar_gregorian_date_from_julian_day_number_test, CalculationTest)
50
50
{
51
51
  int64_t julian_day;
52
52
  uint32_t year_out, month_out, day_out;
53
53
  
54
54
  julian_day= 2455289;
55
55
  gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
56
 
  BOOST_REQUIRE((year_out == 2010) && (month_out == 4) && (day_out == 2));
 
56
  EXPECT_TRUE((year_out == 2010) && (month_out == 4) && (day_out == 2));
57
57
  
58
58
  julian_day= 2443134;
59
59
  gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
60
 
  BOOST_REQUIRE((year_out == 1976) && (month_out == 12) && (day_out == 21));
 
60
  EXPECT_TRUE((year_out == 1976) && (month_out == 12) && (day_out == 21));
61
61
  
62
62
  julian_day= 2469973;
63
63
  gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
64
 
  BOOST_REQUIRE((year_out == 2050) && (month_out == 6) && (day_out == 15));
 
64
  EXPECT_TRUE((year_out == 2050) && (month_out == 6) && (day_out == 15));
65
65
  
66
66
  julian_day= 2451544;
67
67
  gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
68
 
  BOOST_REQUIRE((year_out == 1999) && (month_out == 12) && (day_out == 31));
 
68
  EXPECT_TRUE((year_out == 1999) && (month_out == 12) && (day_out == 31));
69
69
  
70
70
  julian_day= 2454526;
71
71
  gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out);
72
 
  BOOST_REQUIRE((year_out == 2008) && (month_out == 2) && (day_out == 29));
73
 
}
74
 
BOOST_AUTO_TEST_SUITE_END()
75
 
 
76
 
BOOST_AUTO_TEST_SUITE(DayOfWeek)
77
 
BOOST_AUTO_TEST_CASE(MondayFirst)
78
 
{
79
 
  /* Friday 2010 IV 2 */
80
 
  BOOST_REQUIRE_EQUAL(4, day_of_week(2455289, false));
81
 
}
82
 
 
83
 
BOOST_AUTO_TEST_CASE(SundayFirst)
84
 
{
85
 
  /* Friday 2010 IV 2 */
86
 
  BOOST_REQUIRE_EQUAL(5, day_of_week(2455289, true));
87
 
}
88
 
BOOST_AUTO_TEST_SUITE_END()
89
 
 
90
 
 
91
 
BOOST_AUTO_TEST_SUITE(CalendarInUnixEpochRange)
92
 
BOOST_AUTO_TEST_CASE(MinOfRange)
 
72
  EXPECT_TRUE((year_out == 2008) && (month_out == 2) && (day_out == 29));
 
73
}
 
74
 
 
75
 
 
76
 
 
77
 
 
78
TEST(calendar_day_of_week_test, MondayFirst)
 
79
{
 
80
  /* Friday 2010 IV 2 */
 
81
  ASSERT_EQ(4, day_of_week(2455289, false));
 
82
}
 
83
 
 
84
TEST(calendar_day_of_week_test, SundayFirst)
 
85
{
 
86
  /* Friday 2010 IV 2 */
 
87
  ASSERT_EQ(5, day_of_week(2455289, true));
 
88
}
 
89
 
 
90
 
 
91
 
 
92
 
 
93
TEST(calendar_in_unix_epoch_range_test, MinOfRange)
93
94
{
94
95
  uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0;
95
96
 
96
 
  BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second));
 
97
  ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
97
98
}
98
99
 
99
 
BOOST_AUTO_TEST_CASE(MaxOfRange)
 
100
TEST(calendar_in_unix_epoch_range_test, MaxOfRange)
100
101
{
101
102
  uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7;
102
103
 
103
 
  BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second));
 
104
  ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
104
105
}
105
106
 
106
 
BOOST_AUTO_TEST_CASE(OneSecondBeforeMinOfRange)
 
107
TEST(calendar_in_unix_epoch_range_test, OneSecondBeforeMinOfRange)
107
108
{
108
109
  uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59;
109
110
 
110
 
  BOOST_REQUIRE(not in_unix_epoch_range(year, month, day, hour, minute, second));
 
111
  ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second));
111
112
}
112
113
 
113
 
BOOST_AUTO_TEST_CASE(OneSecondAfterMaxOfRange)
 
114
TEST(calendar_in_unix_epoch_range_test, OneSecondAfterMaxOfRange)
114
115
{
115
116
  uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8;
116
117
 
117
 
  BOOST_REQUIRE(not in_unix_epoch_range(year, month, day, hour, minute, second));
 
118
  ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second));
118
119
}
119
120
 
120
 
BOOST_AUTO_TEST_CASE(InsideRange)
 
121
TEST(calendar_in_unix_epoch_range_test, InsideRange)
121
122
{
122
123
  uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5;
123
 
  BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second));
 
124
  EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
124
125
 
125
126
  year= 2010; month= 4; day= 2; hour= 21; minute= 44; second= 0;
126
 
  BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second));
 
127
  EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
127
128
 
128
129
  year= 2020; month= 7; day= 13; hour= 16; minute= 56; second= 59;
129
 
  BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second));
 
130
  EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second));
130
131
}
131
 
BOOST_AUTO_TEST_SUITE_END()