Fix GsweTimestamp tests
This commit is contained in:
parent
e16c4eca70
commit
b77aae9f5c
@ -4,13 +4,20 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <swe-glib.h>
|
#include <swe-glib.h>
|
||||||
|
|
||||||
|
#include "test-asserts.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_timestamp_jd(void)
|
test_timestamp_jd(void)
|
||||||
{
|
{
|
||||||
GsweTimestamp *timestamp;
|
GsweTimestamp *timestamp;
|
||||||
gdouble jd;
|
gdouble jd,
|
||||||
|
seconds;
|
||||||
|
|
||||||
timestamp = gswe_timestamp_new_from_gregorian_full(1983, 3, 7, 11, 54, 45, 0, 1.0);
|
timestamp = gswe_timestamp_new_from_gregorian_full(
|
||||||
|
1983, 3, 7,
|
||||||
|
11, 54, 45, 0,
|
||||||
|
1.0
|
||||||
|
);
|
||||||
g_assert(timestamp);
|
g_assert(timestamp);
|
||||||
|
|
||||||
jd = gswe_timestamp_get_julian_day_et(timestamp, NULL);
|
jd = gswe_timestamp_get_julian_day_et(timestamp, NULL);
|
||||||
@ -19,16 +26,44 @@ test_timestamp_jd(void)
|
|||||||
|
|
||||||
timestamp = gswe_timestamp_new_from_julian_day(jd);
|
timestamp = gswe_timestamp_new_from_julian_day(jd);
|
||||||
g_assert(timestamp);
|
g_assert(timestamp);
|
||||||
g_assert(gswe_timestamp_get_gregorian_timezone(timestamp) == 1.0);
|
gswe_timestamp_set_gregorian_timezone(timestamp, 1.0, NULL);
|
||||||
g_assert(gswe_timestamp_get_gregorian_year(timestamp, NULL) == 1983);
|
g_assert_cmpfloat(
|
||||||
g_assert(gswe_timestamp_get_gregorian_month(timestamp, NULL) == 3);
|
gswe_timestamp_get_gregorian_timezone(timestamp),
|
||||||
g_assert(gswe_timestamp_get_gregorian_day(timestamp, NULL) == 7);
|
==,
|
||||||
g_assert(gswe_timestamp_get_gregorian_hour(timestamp, NULL) == 11);
|
1.0
|
||||||
g_assert(gswe_timestamp_get_gregorian_minute(timestamp, NULL) == 54);
|
);
|
||||||
/* The next two lines seem to provide an inaccurate result due to floating
|
g_assert_cmpint(
|
||||||
* point inaccuracies (may give 44.999999 instead of 45.0) */
|
gswe_timestamp_get_gregorian_year(timestamp, NULL),
|
||||||
// g_assert(gswe_timestamp_get_gregorian_second(timestamp, NULL) == 45);
|
==,
|
||||||
// g_assert(gswe_timestamp_get_gregorian_microsecond(timestamp, NULL) == 0);
|
1983
|
||||||
|
);
|
||||||
|
g_assert_cmpuint(
|
||||||
|
gswe_timestamp_get_gregorian_month(timestamp, NULL),
|
||||||
|
==,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
g_assert_cmpuint(gswe_timestamp_get_gregorian_day(timestamp, NULL), ==, 7);
|
||||||
|
g_assert_cmpuint(
|
||||||
|
gswe_timestamp_get_gregorian_hour(timestamp, NULL),
|
||||||
|
==,
|
||||||
|
11
|
||||||
|
);
|
||||||
|
g_assert_cmpuint(
|
||||||
|
gswe_timestamp_get_gregorian_minute(timestamp, NULL),
|
||||||
|
==,
|
||||||
|
54
|
||||||
|
);
|
||||||
|
|
||||||
|
seconds =
|
||||||
|
gswe_timestamp_get_gregorian_second(timestamp, NULL)
|
||||||
|
+ gswe_timestamp_get_gregorian_microsecond(timestamp, NULL) / 1000.0;
|
||||||
|
|
||||||
|
/* Due to floating point errors, we allow 5 microseconds fuzzyness here */
|
||||||
|
gswe_assert_fuzzy_equals(
|
||||||
|
seconds,
|
||||||
|
45.0,
|
||||||
|
0.005
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
27
tests/test-asserts.h
Normal file
27
tests/test-asserts.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef __SWE_GLIB_TEST_ASSERTS_H__
|
||||||
|
#define __SWE_GLIB_TEST_ASSERTS_H__
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
/* Check equality with fuzzyness. Thanks for ebassi@GNOME and graphene */
|
||||||
|
#define gswe_assert_fuzzy_equals(n1,n2,epsilon) \
|
||||||
|
G_STMT_START { \
|
||||||
|
typeof ((n1)) __n1 = (n1); \
|
||||||
|
typeof ((n2)) __n2 = (n2); \
|
||||||
|
typeof ((epsilon)) __epsilon = (epsilon); \
|
||||||
|
if (__n1 > __n2) { \
|
||||||
|
if ((__n1 - __n2) <= __epsilon) ; else { \
|
||||||
|
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
#n1 " == " #n2 " (+/- " #epsilon ")", \
|
||||||
|
__n1, "==", __n2, 'f'); \
|
||||||
|
} \
|
||||||
|
} else { \
|
||||||
|
if ((__n2 - __n1) <= __epsilon) ; else { \
|
||||||
|
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
#n1 " == " #n2 " (+/- " #epsilon ")", \
|
||||||
|
__n1, "==", __n2, 'f'); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} G_STMT_END
|
||||||
|
|
||||||
|
#endif /* __SWE_GLIB_TEST_ASSERTS_H__ */
|
Loading…
x
Reference in New Issue
Block a user