Skip to content

Commit d4fca33

Browse files
update cases
1 parent 90a490a commit d4fca33

File tree

2 files changed

+0
-219
lines changed

2 files changed

+0
-219
lines changed

code/tests/cases/test_datetime.c

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -140,128 +140,6 @@ FOSSIL_TEST(c_test_time_add_span) {
140140
ASSUME_ITS_EQUAL_I32(dt.second, 15);
141141
}
142142

143-
FOSSIL_TEST(c_test_time_now_edge_cases) {
144-
fossil_sys_time_datetime_t dt;
145-
fossil_sys_time_now(&dt);
146-
// Check for reasonable ranges
147-
ASSUME_ITS_TRUE(dt.year >= 1970); // Should not be before epoch
148-
ASSUME_ITS_TRUE(dt.month >= 1 && dt.month <= 12);
149-
ASSUME_ITS_TRUE(dt.day >= 1 && dt.day <= 31);
150-
ASSUME_ITS_TRUE(dt.hour >= 0 && dt.hour <= 23);
151-
ASSUME_ITS_TRUE(dt.minute >= 0 && dt.minute <= 59);
152-
ASSUME_ITS_TRUE(dt.second >= 0 && dt.second <= 60); // Allow leap second
153-
}
154-
155-
FOSSIL_TEST(c_test_time_format_edge_cases) {
156-
fossil_sys_time_datetime_t dt = {9999, 12, 31, 23, 59, 59, 999999999};
157-
char buffer[10];
158-
int len = fossil_sys_time_format(&dt, buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", 1);
159-
ASSUME_ITS_TRUE(len < (int)sizeof(buffer)); // Buffer too small, should truncate or error
160-
fossil_sys_time_datetime_t dt2 = {2024, 2, 29, 0, 0, 0, 0};
161-
char buffer2[100];
162-
fossil_sys_time_format(&dt2, buffer2, sizeof(buffer2), "%Y-%m-%d", 1);
163-
ASSUME_ITS_TRUE(strcmp(buffer2, "2024-02-29") == 0); // Leap day format
164-
}
165-
166-
FOSSIL_TEST(c_test_time_is_leap_year_edge_cases) {
167-
ASSUME_ITS_TRUE(fossil_sys_time_is_leap_year(2000) == 1); // Divisible by 400
168-
ASSUME_ITS_TRUE(fossil_sys_time_is_leap_year(1900) == 0); // Divisible by 100, not 400
169-
ASSUME_ITS_TRUE(fossil_sys_time_is_leap_year(2400) == 1); // Far future leap year
170-
ASSUME_ITS_TRUE(fossil_sys_time_is_leap_year(2100) == 0); // Divisible by 100, not 400
171-
}
172-
173-
FOSSIL_TEST(c_test_time_days_in_month_edge_cases) {
174-
ASSUME_ITS_TRUE(fossil_sys_time_days_in_month(2024, 0) == 0); // Invalid month
175-
ASSUME_ITS_TRUE(fossil_sys_time_days_in_month(2024, 13) == 0); // Invalid month
176-
ASSUME_ITS_TRUE(fossil_sys_time_days_in_month(2024, 4) == 30); // April
177-
ASSUME_ITS_TRUE(fossil_sys_time_days_in_month(2024, 12) == 31); // December
178-
}
179-
180-
FOSSIL_TEST(c_test_time_add_seconds_edge_cases) {
181-
fossil_sys_time_datetime_t dt = {2024, 2, 28, 23, 59, 59, 0};
182-
fossil_sys_time_add_seconds(&dt, 86400); // Add one day, should be Feb 29 (leap year)
183-
ASSUME_ITS_EQUAL_I32(dt.year, 2024);
184-
ASSUME_ITS_EQUAL_I32(dt.month, 2);
185-
ASSUME_ITS_EQUAL_I32(dt.day, 29);
186-
dt = (fossil_sys_time_datetime_t){2023, 2, 28, 23, 59, 59, 0};
187-
fossil_sys_time_add_seconds(&dt, 86400); // Add one day, should be Mar 1 (not leap year)
188-
ASSUME_ITS_EQUAL_I32(dt.year, 2023);
189-
ASSUME_ITS_EQUAL_I32(dt.month, 3);
190-
ASSUME_ITS_EQUAL_I32(dt.day, 1);
191-
}
192-
193-
FOSSIL_TEST(c_test_time_diff_seconds_edge_cases) {
194-
fossil_sys_time_datetime_t a = {2024, 1, 1, 0, 0, 0, 0};
195-
fossil_sys_time_datetime_t b = {2023, 1, 1, 0, 0, 0, 0};
196-
int64_t diff = fossil_sys_time_diff_seconds(&a, &b);
197-
ASSUME_ITS_TRUE(diff > 0); // Should be positive
198-
fossil_sys_time_datetime_t c = {2024, 1, 1, 0, 0, 0, 0};
199-
fossil_sys_time_datetime_t d = {2024, 1, 1, 0, 0, 0, 0};
200-
ASSUME_ITS_EQUAL_I64(fossil_sys_time_diff_seconds(&c, &d), 0); // Same time
201-
}
202-
203-
FOSSIL_TEST(c_test_time_normalize_edge_cases) {
204-
fossil_sys_time_datetime_t dt = {2024, 12, 31, 23, 59, 120, 0};
205-
fossil_sys_time_normalize(&dt);
206-
ASSUME_ITS_EQUAL_I32(dt.year, 2025);
207-
ASSUME_ITS_EQUAL_I32(dt.month, 1);
208-
ASSUME_ITS_EQUAL_I32(dt.day, 1);
209-
ASSUME_ITS_EQUAL_I32(dt.second, 0);
210-
}
211-
212-
FOSSIL_TEST(c_test_time_validate_edge_cases) {
213-
fossil_sys_time_datetime_t invalid_month = {2024, 13, 1, 0, 0, 0, 0};
214-
fossil_sys_time_datetime_t invalid_day = {2024, 2, 30, 0, 0, 0, 0};
215-
fossil_sys_time_datetime_t invalid_hour = {2024, 1, 1, 24, 0, 0, 0};
216-
ASSUME_ITS_FALSE(fossil_sys_time_validate(&invalid_month));
217-
ASSUME_ITS_FALSE(fossil_sys_time_validate(&invalid_day));
218-
ASSUME_ITS_FALSE(fossil_sys_time_validate(&invalid_hour));
219-
}
220-
221-
FOSSIL_TEST(c_test_time_unix_conversion_edge_cases) {
222-
fossil_sys_time_datetime_t dt = {2038, 1, 19, 3, 14, 7, 0}; // 32-bit overflow
223-
int64_t ts = fossil_sys_time_to_unix(&dt);
224-
ASSUME_ITS_TRUE(ts > 0);
225-
fossil_sys_time_datetime_t dt2;
226-
fossil_sys_time_from_unix(ts, &dt2);
227-
ASSUME_ITS_EQUAL_I32(dt2.year, 2038);
228-
ASSUME_ITS_EQUAL_I32(dt2.month, 1);
229-
ASSUME_ITS_EQUAL_I32(dt2.day, 19);
230-
}
231-
232-
FOSSIL_TEST(c_test_time_monotonic_ns_edge_cases) {
233-
uint64_t t1 = fossil_sys_time_monotonic_ns();
234-
fossil_sys_time_sleep_ns(0); // No sleep
235-
uint64_t t2 = fossil_sys_time_monotonic_ns();
236-
ASSUME_ITS_TRUE(t2 >= t1); // Should not go backwards
237-
}
238-
239-
FOSSIL_TEST(c_test_time_span_edge_cases) {
240-
fossil_sys_time_span_t span = fossil_sys_time_span_from_seconds(-1); // Negative seconds
241-
ASSUME_ITS_TRUE(span.days <= 0);
242-
ASSUME_ITS_TRUE(span.hours <= 0);
243-
ASSUME_ITS_TRUE(span.minutes <= 0);
244-
ASSUME_ITS_TRUE(span.seconds <= 0);
245-
246-
fossil_sys_time_span_t zero_span = fossil_sys_time_span_from_seconds(0);
247-
ASSUME_ITS_EQUAL_I64(zero_span.days, 0);
248-
ASSUME_ITS_EQUAL_I64(zero_span.hours, 0);
249-
ASSUME_ITS_EQUAL_I64(zero_span.minutes, 0);
250-
ASSUME_ITS_EQUAL_I64(zero_span.seconds, 0);
251-
}
252-
253-
FOSSIL_TEST(c_test_time_add_span_edge_cases) {
254-
fossil_sys_time_datetime_t dt = {2024, 12, 31, 23, 59, 59, 0};
255-
fossil_sys_time_span_t span = {.days = 0, .hours = 0, .minutes = 0, .seconds = 2, .nanoseconds = 0};
256-
fossil_sys_time_add_span(&dt, &span);
257-
ASSUME_ITS_EQUAL_I32(dt.year, 2025);
258-
ASSUME_ITS_EQUAL_I32(dt.month, 1);
259-
ASSUME_ITS_EQUAL_I32(dt.day, 1);
260-
ASSUME_ITS_EQUAL_I32(dt.hour, 0);
261-
ASSUME_ITS_EQUAL_I32(dt.minute, 0);
262-
ASSUME_ITS_EQUAL_I32(dt.second, 1);
263-
}
264-
265143
// * * * * * * * * * * * * * * * * * * * * * * * *
266144
// * Fossil Logic Test Pool
267145
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -279,18 +157,6 @@ FOSSIL_TEST_GROUP(c_time_tests) {
279157
FOSSIL_TEST_ADD(c_time_suite, c_test_time_monotonic_ns);
280158
FOSSIL_TEST_ADD(c_time_suite, c_test_time_span);
281159
FOSSIL_TEST_ADD(c_time_suite, c_test_time_add_span);
282-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_now_edge_cases);
283-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_format_edge_cases);
284-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_is_leap_year_edge_cases);
285-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_days_in_month_edge_cases);
286-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_add_seconds_edge_cases);
287-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_diff_seconds_edge_cases);
288-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_normalize_edge_cases);
289-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_validate_edge_cases);
290-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_unix_conversion_edge_cases);
291-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_monotonic_ns_edge_cases);
292-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_span_edge_cases);
293-
FOSSIL_TEST_ADD(c_time_suite, c_test_time_add_span_edge_cases);
294160

295161
FOSSIL_TEST_REGISTER(c_time_suite);
296162
}

code/tests/cases/test_datetime.cpp

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -156,83 +156,6 @@ FOSSIL_TEST(cpp_test_monotonic_ns_and_sleep_ns) {
156156
ASSUME_ITS_TRUE(t2 > t1);
157157
}
158158

159-
FOSSIL_TEST(cpp_test_time_now_edge_cases) {
160-
fossil::sys::DateTime dt;
161-
auto datetime = dt.get();
162-
// Check for valid hour, minute, second ranges
163-
ASSUME_ITS_TRUE(datetime.hour >= 0 && datetime.hour <= 23);
164-
ASSUME_ITS_TRUE(datetime.minute >= 0 && datetime.minute <= 59);
165-
ASSUME_ITS_TRUE(datetime.second >= 0 && datetime.second <= 59);
166-
}
167-
168-
FOSSIL_TEST(cpp_test_time_format_edge_cases) {
169-
fossil::sys::DateTime dt({2024, 12, 31, 23, 59, 59, 999});
170-
std::string formatted = dt.format("%Y-%m-%d %H:%M:%S.%f", true);
171-
ASSUME_ITS_TRUE(formatted == "2024-12-31 23:59:59.999");
172-
// Test formatting with single-digit month/day
173-
fossil::sys::DateTime dt2({2024, 2, 3, 4, 5, 6, 7});
174-
std::string formatted2 = dt2.format("%Y-%m-%d %H:%M:%S", true);
175-
ASSUME_ITS_TRUE(formatted2 == "2024-02-03 04:05:06");
176-
}
177-
178-
FOSSIL_TEST(cpp_test_time_is_leap_year_edge_cases) {
179-
// Test century years
180-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2000, 1, 1).is_leap_year() == true); // 2000 is leap
181-
ASSUME_ITS_TRUE(fossil::sys::Calendar(1900, 1, 1).is_leap_year() == false); // 1900 is not leap
182-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2400, 1, 1).is_leap_year() == true); // 2400 is leap
183-
}
184-
185-
FOSSIL_TEST(cpp_test_time_days_in_month_edge_cases) {
186-
// April, June, September, November have 30 days
187-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2024, 4, 1).days_in_month() == 30);
188-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2024, 6, 1).days_in_month() == 30);
189-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2024, 9, 1).days_in_month() == 30);
190-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2024, 11, 1).days_in_month() == 30);
191-
// February in year 2100 (not leap)
192-
ASSUME_ITS_TRUE(fossil::sys::Calendar(2100, 2, 1).days_in_month() == 28);
193-
}
194-
195-
FOSSIL_TEST(cpp_test_datetime_constructor_edge_cases) {
196-
// Construct with minimum valid date
197-
fossil::sys::DateTime dt_min({1, 1, 1, 0, 0, 0, 0});
198-
auto datetime_min = dt_min.get();
199-
ASSUME_ITS_TRUE(datetime_min.year == 1);
200-
ASSUME_ITS_TRUE(datetime_min.month == 1);
201-
ASSUME_ITS_TRUE(datetime_min.day == 1);
202-
// Construct with maximum valid date (example: year 9999)
203-
fossil::sys::DateTime dt_max({9999, 12, 31, 23, 59, 59, 999});
204-
auto datetime_max = dt_max.get();
205-
ASSUME_ITS_TRUE(datetime_max.year == 9999);
206-
ASSUME_ITS_TRUE(datetime_max.month == 12);
207-
ASSUME_ITS_TRUE(datetime_max.day == 31);
208-
}
209-
210-
FOSSIL_TEST(cpp_test_datetime_format_invalid_format) {
211-
fossil::sys::DateTime dt({2024, 1, 1, 12, 0, 0, 0});
212-
std::string formatted = dt.format("invalid_format_string", true);
213-
ASSUME_ITS_TRUE(!formatted.empty()); // Should not crash, may return input or fallback
214-
}
215-
216-
FOSSIL_TEST(cpp_test_datetime_add_seconds_edge_cases) {
217-
fossil::sys::DateTime dt({2024, 12, 31, 23, 59, 59, 0});
218-
dt.add_seconds(1); // Should roll over to next year
219-
auto datetime = dt.get();
220-
ASSUME_ITS_TRUE(datetime.year == 2025 && datetime.month == 1 && datetime.day == 1 && datetime.hour == 0 && datetime.minute == 0 && datetime.second == 0);
221-
dt.add_seconds(-1); // Should roll back to previous year end
222-
datetime = dt.get();
223-
ASSUME_ITS_TRUE(datetime.year == 2024 && datetime.month == 12 && datetime.day == 31 && datetime.hour == 23 && datetime.minute == 59 && datetime.second == 59);
224-
}
225-
226-
FOSSIL_TEST(cpp_test_datetime_diff_seconds_edge_cases) {
227-
fossil::sys::DateTime dt1({2024, 1, 1, 0, 0, 0, 0});
228-
fossil::sys::DateTime dt2({2023, 12, 31, 23, 59, 59, 0});
229-
int64_t diff = dt1.diff_seconds(dt2);
230-
ASSUME_ITS_TRUE(diff == 1); // 1 second difference
231-
// Negative difference
232-
int64_t diff_neg = dt2.diff_seconds(dt1);
233-
ASSUME_ITS_TRUE(diff_neg == -1);
234-
}
235-
236159
// * * * * * * * * * * * * * * * * * * * * * * * *
237160
// * Fossil Logic Test Pool
238161
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -254,14 +177,6 @@ FOSSIL_TEST_GROUP(cpp_time_tests) {
254177
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_datetime_add_span);
255178
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_timespan_constructors_and_conversion);
256179
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_monotonic_ns_and_sleep_ns);
257-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_time_now_edge_cases);
258-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_time_format_edge_cases);
259-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_time_is_leap_year_edge_cases);
260-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_time_days_in_month_edge_cases);
261-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_datetime_constructor_edge_cases);
262-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_datetime_format_invalid_format);
263-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_datetime_add_seconds_edge_cases);
264-
FOSSIL_TEST_ADD(cpp_time_suite, cpp_test_datetime_diff_seconds_edge_cases);
265180

266181
FOSSIL_TEST_REGISTER(cpp_time_suite);
267182
}

0 commit comments

Comments
 (0)