END_TEST START_TEST(test_set_rational) { unsigned int i; struct sr_rational r; const int64_t p[] = {0, 1, -5, INT64_MAX}; const uint64_t q[] = {0, 2, 7, UINT64_MAX}; for (i = 0; i < ARRAY_SIZE(p); i++) { sr_rational_set(&r, p[i], q[i]); fail_unless(r.p == p[i] && r.q == q[i]); } }
/** * This function takes a value of the form "2.000E-03" and returns the index * of an array where a matching pair was found. * * @param value The string to be parsed. * @param array The array of s/f pairs. * @param array_len The number of pairs in the array. * @param result The index at which a matching pair was found. * * @return SR_ERR on any parsing error, SR_OK otherwise. */ static int array_float_get(gchar *value, const uint64_t array[][2], int array_len, unsigned int *result) { struct sr_rational rval; struct sr_rational aval; if (sr_parse_rational(value, &rval) != SR_OK) return SR_ERR; for (int i = 0; i < array_len; i++) { sr_rational_set(&aval, array[i][0], array[i][1]); if (sr_rational_eq(&rval, &aval)) { *result = i; return SR_OK; } } return SR_ERR; }
END_TEST START_TEST(test_set_rational_null) { sr_rational_set(NULL, 5, 7); }