-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imrat: fix an inconsistency in reading string values (#62)
Make mp_rat_read_cstring more consistent with mp_int_read_cstring. Add some tests for that. Updates #57
- Loading branch information
1 parent
2a5176f
commit 2a071f1
Showing
4 changed files
with
47 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdio.h> | ||
|
||
#include "imrat.h" | ||
|
||
struct test { | ||
char* input; | ||
int radix; | ||
mp_result want; | ||
}; | ||
|
||
int main(int arch, char* argv[]) { | ||
struct test tests[] = { | ||
{"123", 10, 0}, | ||
{" 1ca", 16, 0}, | ||
{"1010", 2, 0}, | ||
{"123 ", 10, -5}, /* MP_TRUNC */ | ||
{"123/456", 8, 0}, | ||
{"123 / 456", 8, 0}, | ||
{"123 /", 8, -4}, /* MP_UNDEF */ | ||
{" -5/-3", 10, 0}, | ||
{NULL, 10, 0}, | ||
}; | ||
|
||
int errs = 0; | ||
for (int i = 0; tests[i].input != NULL; i++) { | ||
mpq_t value; | ||
mp_rat_init(&value); | ||
|
||
mp_result got = mp_rat_read_cstring(&value, tests[i].radix, tests[i].input, NULL); | ||
if (got != tests[i].want) { | ||
printf("ERROR: test %d: input \"%s\": got \"%s\", want \"%s\"\n", | ||
i+1, tests[i].input, mp_error_string(got), mp_error_string(tests[i].want)); | ||
} | ||
} | ||
printf("REGRESSION: mp_rat_read_cstring inconsistent space handling: %s\n", | ||
errs ? "FAILED" : "OK"); | ||
return !errs; | ||
} |
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