Testing: Julian dates

This commit is contained in:
shahramn 2024-02-28 13:54:02 +00:00
parent 29fb827391
commit 1eb99c0bf8
1 changed files with 20 additions and 7 deletions

View File

@ -14,18 +14,14 @@
#define EPSILON 1e-12
#define DBL_EQUAL(a, b) (fabs((a) - (b)) <= (EPSILON)*fabs((a)))
#define BOOL int
#define TRUE 1
#define FALSE 0
static BOOL Check(
static bool Check(
const long year1, const long month1, const long day1, const long hour1, const long min1, const long sec1,
const long year2, const long month2, const long day2, const long hour2, const long min2, const long sec2)
{
if (year1 != year2 || month1 != month2 || day1 != day2 || hour1 != hour2 || min1 != min2 || sec1 != sec2) {
return FALSE;
return false;
}
return TRUE;
return true;
}
static void TestDateTime(const long year, const long month, const long day, const long hour, const long min, const long sec)
@ -184,6 +180,7 @@ static void Test3()
static void Test4()
{
const long iyear = 1582;
printf("Test4...\n");
TestDateTime(iyear, 9, 1, 1, 0, 0);
TestDateTime(iyear, 9, 2, 1, 0, 0);
@ -215,6 +212,21 @@ static void Test4()
*/
}
static void Test5()
{
printf("Test5...\n");
double jd = 0.0;
long year=2017, month=2, day=29, hour=0, min=0, sec=0; // Feb 2017 had 28 days
long year1, month1, day1, hour1, min1, sec1;
codes_datetime_to_julian(year, month, day, hour, min, sec, &jd);
codes_julian_to_datetime(jd, &year1, &month1, &day1, &hour1, &min1, &sec1);
if (Check(year, month, day, hour, min, sec, year1, month1, day1, hour1, min1, sec1)) {
Assert(!"Bad input should have failed checks");
}
}
int main(int argc, char* argv[])
{
Test0();
@ -222,6 +234,7 @@ int main(int argc, char* argv[])
Test2();
Test3();
Test4();
Test5();
printf("All OK\n");
return 0;
}