summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2005-12-05 12:33:44 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2005-12-05 12:33:44 +0000
commit30dab643af80f1ab0c11963bc72822d1ab28351a (patch)
tree84b370871d7115179d097ab8cea2500cada5ccea
parent774d99069ce9099b3fcc3b1222c817df8da3dbc8 (diff)
really add the tests for the 64/double conversion
Original commit message from CVS: really add the tests for the 64/double conversion
-rw-r--r--tests/check/gst/gstutils.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/check/gst/gstutils.c b/tests/check/gst/gstutils.c
index 2812420e3f..cca7d0b638 100644
--- a/tests/check/gst/gstutils.c
+++ b/tests/check/gst/gstutils.c
@@ -272,6 +272,58 @@ GST_START_TEST (test_math_scale_random)
GST_END_TEST;
+GST_START_TEST (test_guint64_to_gdouble)
+{
+ guint64 from[] = { 0, 1, 100, 10000, G_GINT64_CONSTANT (1) << 63,
+ (G_GINT64_CONSTANT (1) << 63) + 1,
+ (G_GINT64_CONSTANT (1) << 63) + (G_GINT64_CONSTANT (1) << 62)
+ };
+ gdouble to[] = { 0., 1., 100., 10000., 9223372036854775808.,
+ 9223372036854775809., 13835058055282163712.
+ };
+ gdouble tolerance[] = { 0., 0., 0., 0., 0., 1., 1. };
+ gint i;
+ gdouble result;
+ gdouble delta;
+
+ for (i = 0; i < G_N_ELEMENTS (from); ++i) {
+ result = gst_util_guint64_to_gdouble (from[i]);
+ delta = ABS (to[i] - result);
+ fail_unless (delta <= tolerance[i],
+ "Could not convert %d: %" G_GUINT64_FORMAT
+ " -> %f, got %f instead, delta of %e with tolerance of %e",
+ i, from[i], to[i], result, delta, tolerance[i]);
+ }
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_gdouble_to_guint64)
+{
+ gdouble from[] = { 0., 1., 100., 10000., 9223372036854775808.,
+ 9223372036854775809., 13835058055282163712.
+ };
+ guint64 to[] = { 0, 1, 100, 10000, G_GINT64_CONSTANT (1) << 63,
+ (G_GINT64_CONSTANT (1) << 63) + 1,
+ (G_GINT64_CONSTANT (1) << 63) + (G_GINT64_CONSTANT (1) << 62)
+ };
+ guint64 tolerance[] = { 0, 0, 0, 0, 0, 1, 1 };
+ gint i;
+ gdouble result;
+ guint64 delta;
+
+ for (i = 0; i < G_N_ELEMENTS (from); ++i) {
+ result = gst_util_gdouble_to_guint64 (from[i]);
+ delta = ABS (to[i] - result);
+ fail_unless (delta <= tolerance[i],
+ "Could not convert %f: %" G_GUINT64_FORMAT
+ " -> %d, got %d instead, delta of %e with tolerance of %e",
+ i, from[i], to[i], result, delta, tolerance[i]);
+ }
+}
+
+GST_END_TEST;
+
Suite *
gst_utils_suite (void)
{
@@ -284,6 +336,8 @@ gst_utils_suite (void)
tcase_add_test (tc_chain, test_math_scale);
tcase_add_test (tc_chain, test_math_scale_uint64);
tcase_add_test (tc_chain, test_math_scale_random);
+ tcase_add_test (tc_chain, test_guint64_to_gdouble);
+ tcase_add_test (tc_chain, test_gdouble_to_guint64);
return s;
}