-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
349 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2021-2025 - Soroush Rabiei, <[email protected]> | ||
* This file is part of libcalendar. | ||
* | ||
* libcalendar is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* libcalendar is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libcalendar. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <libcalendars/cl-gregorian.h> | ||
#include "calendar-arithmetic.h" | ||
|
||
void test_julian_day( | ||
void (*cal_to_jdn)(uint32_t*, int16_t, uint8_t, uint16_t), | ||
void (*jdn_to_cal)(uint32_t, int16_t*, uint8_t*, uint16_t*), | ||
uint32_t in_jd, uint32_t* out_jd) | ||
{ | ||
int16_t year; | ||
uint8_t month; | ||
uint16_t day; | ||
(*jdn_to_cal)(in_jd, &year, &month, &day); | ||
(*cal_to_jdn)(out_jd, year, month, day); | ||
} | ||
|
||
void test_gregorian_calendar( | ||
void (*cal_to_gr)(int16_t, uint8_t, uint16_t, int16_t*, uint8_t*, uint16_t*), | ||
void (*gr_to_cal)(int16_t, uint8_t, uint16_t, int16_t*, uint8_t*, uint16_t*), | ||
uint32_t in_jd, int16_t* gyi, uint8_t* gmi, uint16_t* gdi, int16_t* gyo, uint8_t* gmo, uint16_t* gdo) | ||
{ | ||
int16_t year; | ||
uint8_t month; | ||
uint16_t day; | ||
jdn_to_gr(in_jd, gyi, gmi, gdi); | ||
(*gr_to_cal)(*gyi, *gmi, *gdi, &year, &month, &day); | ||
(*cal_to_gr)(year, month, day, gyo, gmo, gdo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2021-2025 - Soroush Rabiei, <[email protected]> | ||
* This file is part of libcalendar. | ||
* | ||
* libcalendar is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* libcalendar is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libcalendar. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "calendar-arithmetic.hpp" | ||
|
||
CalendarArithmetic::CalendarArithmetic() | ||
: ::testing::Test() | ||
, min_jdn(0) | ||
, max_jdn(0) | ||
{ | ||
} | ||
|
||
void CalendarArithmetic::SetRange(uint32_t min_jdn_, uint32_t max_jdn_) | ||
{ | ||
this->min_jdn = min_jdn_; | ||
this->max_jdn = max_jdn_; | ||
} | ||
|
||
void CalendarArithmetic::JulianDay(CalendarArithmetic::jdn_to_calendar to_calendar, CalendarArithmetic::calendar_to_jdn to_jdn) | ||
{ | ||
ASSERT_NE(to_calendar, nullptr) << "`to_calendar` function not set."; | ||
ASSERT_NE(to_jdn, nullptr) << "`to_jdn` function not set."; | ||
uint32_t jdn = 0; | ||
uint32_t jdn2 = 0; | ||
for (jdn = min_jdn; jdn < max_jdn; ++jdn) | ||
{ | ||
int16_t year; | ||
uint8_t month; | ||
uint16_t day; | ||
to_calendar(jdn, &year, &month, &day); | ||
to_jdn(&jdn2, year, month, day); | ||
ASSERT_EQ(jdn2, jdn); | ||
} | ||
} | ||
|
||
void CalendarArithmetic::Gregorian(CalendarArithmetic::jdn_to_calendar to_calendar, | ||
CalendarArithmetic::calendar_to_calendar cal_to_gr, | ||
CalendarArithmetic::calendar_to_calendar gr_to_cal) | ||
{ | ||
uint32_t jdn = 0; | ||
uint32_t jdn2 = 0; | ||
for (jdn = min_jdn; jdn < max_jdn; ++jdn) | ||
{ | ||
int16_t gy[2] = {0, 0}; | ||
uint8_t gm[2] = {0, 0}; | ||
uint16_t gd[2] = {0, 0}; | ||
int16_t year; | ||
uint8_t month; | ||
uint16_t day; | ||
|
||
to_calendar(jdn, &gy[0], &gm[0], &gd[0]); | ||
gr_to_cal(gy[0], gm[0], gd[0], &year, &month, &day); | ||
cal_to_gr(year, month, day, &gy[1], &gm[1], &gd[1]); | ||
|
||
ASSERT_EQ(gy[0], gy[1]); | ||
ASSERT_EQ(gm[0], gm[1]); | ||
ASSERT_EQ(gd[0], gd[1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2021-2025 - Soroush Rabiei, <[email protected]> | ||
* This file is part of libcalendar. | ||
* | ||
* libcalendar is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* libcalendar is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libcalendar. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
void test_julian_day( | ||
void (*cal_to_jdn)(uint32_t*, int16_t, uint8_t, uint16_t), | ||
void (*jdn_to_cal)(uint32_t, int16_t*, uint8_t*, uint16_t*), | ||
uint32_t in_jd, uint32_t* out_jd); | ||
|
||
void test_gregorian_calendar( | ||
void (*cal_to_gr)(int16_t , uint8_t , uint16_t , int16_t*, uint8_t*, uint16_t*), | ||
void (*gr_to_cal)(int16_t , uint8_t , uint16_t , int16_t*, uint8_t*, uint16_t*), | ||
uint32_t in_jd, int16_t*, uint8_t*, uint16_t*, int16_t*, uint8_t*, uint16_t*); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2021-2025 - Soroush Rabiei, <[email protected]> | ||
* This file is part of libcalendar. | ||
* | ||
* libcalendar is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* libcalendar is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with libcalendar. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <gtest/gtest.h> | ||
#include <functional> | ||
|
||
class CalendarArithmetic : public ::testing::Test { | ||
protected: | ||
using jdn_to_calendar = std::function<void(uint32_t, int16_t*, uint8_t*, uint16_t*)>; | ||
using calendar_to_jdn = std::function<void(uint32_t*, int16_t, uint8_t, uint16_t)>; | ||
using calendar_to_calendar = std::function<void(int16_t, uint8_t, uint16_t, int16_t*, uint8_t*, uint16_t*)>; | ||
|
||
CalendarArithmetic(); | ||
|
||
void SetRange(uint32_t min_jdn, uint32_t max_jdn); | ||
void JulianDay(jdn_to_calendar, calendar_to_jdn); | ||
void Gregorian(jdn_to_calendar, calendar_to_calendar, calendar_to_calendar); | ||
|
||
private: | ||
uint32_t min_jdn; | ||
uint32_t max_jdn; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.