Remove the "trailing garbage" version of the mpi_cmp() test. It would

be better to systematically pad MPIs used in all tests with garbage.

Greatly expand the number of mpi_cmp() tests to cover all possible
combinations of same or different sign, same or different msb and same
or different magnitude.
This commit is contained in:
Dag-Erling Smørgrav 2014-12-30 17:00:56 +00:00 committed by des
parent f18b915b67
commit 8d0e24dee7

View file

@ -688,15 +688,61 @@ static struct t_cmp_case {
const char *desc;
int a, b, cmp;
} t_cmp_cases[] = {
{ "-3 == -3", -3, -3, 0 },
{ "-3 < -2", -3, -2, -1 },
{ "-3 < -1", -3, -1, -1 },
{ "-3 < 0", -3, 0, -1 },
{ "-3 < 1", -3, 1, -1 },
{ "-3 < 2", -3, 2, -1 },
{ "-3 < 3", -3, 3, -1 },
{ "-2 > -3", -2, -3, 1 },
{ "-2 == -2", -2, -2, 0 },
{ "-2 < -1", -2, -1, -1 },
{ "-2 < 0", -2, 0, -1 },
{ "-2 < 1", -2, 1, -1 },
{ "-2 < 2", -2, 2, -1 },
{ "-2 < 3", -2, 3, -1 },
{ "-1 > -3", -1, -3, 1 },
{ "-1 > -2", -1, -2, 1 },
{ "-1 == -1", -1, -1, 0 },
{ "-1 < 0", -1, 0, -1 },
{ "-1 < 1", -1, 1, -1 },
{ "-1 < 2", -1, 2, -1 },
{ "-1 < 3", -1, 3, -1 },
{ "0 > -3", 0, -3, 1 },
{ "0 > -2", 0, -2, 1 },
{ "0 > -1", 0, -1, 1 },
{ "0 == 0", 0, 0, 0 },
{ "0 < 1", 0, 1, -1 },
{ "0 < 2", 0, 2, -1 },
{ "0 < 3", 0, 3, -1 },
{ "1 > -3", 1, -3, 1 },
{ "1 > -2", 1, -2, 1 },
{ "1 > -1", 1, -1, 1 },
{ "1 > 0", 1, 0, 1 },
{ "1 == 1", 1, 1, 0 },
{ "1 < 2", 1, 2, -1 },
{ "1 < 3", 1, 3, -1 },
{ "2 > -3", 2, -3, 1 },
{ "2 > -2", 2, -2, 1 },
{ "2 > -1", 2, -1, 1 },
{ "2 > 0", 2, 0, 1 },
{ "2 > 1", 2, 1, 1 },
{ "2 == 2", 2, 2, 0 },
{ "2 < 3", 2, 3, -1 },
{ "3 > -3", 3, -3, 1 },
{ "3 > -2", 3, -2, 1 },
{ "3 > -1", 3, -1, 1 },
{ "3 > 0", 3, 0, 1 },
{ "3 > 1", 3, 1, 1 },
{ "3 > 2", 3, 2, 1 },
{ "3 == 3", 3, 3, 0 },
};
/*
@ -717,26 +763,6 @@ t_mpi_cmp(char **desc CRYB_UNUSED, void *arg)
return (ret);
}
/*
* Compare two MPIs with garbage past the msb
*/
static int
t_mpi_cmp_garbage(char **desc CRYB_UNUSED, void *arg)
{
struct t_cmp_case *tc = arg;
cryb_mpi a = CRYB_MPI_ZERO, b = CRYB_MPI_ZERO;
int ret = 1;
mpi_set(&a, tc->a);
a.words[1] = 2;
mpi_set(&b, tc->b);
b.words[1] = tc->cmp < 1 ? 1 : 3;
ret &= t_compare_i(tc->cmp, mpi_cmp(&a, &b));
mpi_destroy(&a);
mpi_destroy(&b);
return (ret);
}
/***************************************************************************
* Left / right shift
@ -1426,11 +1452,8 @@ t_prepare(int argc, char *argv[])
t_add_test(t_mpi_large_load_fail, NULL, "large load (failure)");
/* comparison */
for (i = 0; i < sizeof t_cmp_cases / sizeof t_cmp_cases[0]; ++i) {
for (i = 0; i < sizeof t_cmp_cases / sizeof t_cmp_cases[0]; ++i)
t_add_test(t_mpi_cmp, &t_cmp_cases[i], t_cmp_cases[i].desc);
t_add_test(t_mpi_cmp_garbage, &t_cmp_cases[i],
"%s (trailing garbage)", t_cmp_cases[i].desc);
}
/* left / right shift */
for (i = 0; i < sizeof t_lsh_cases / sizeof t_lsh_cases[0]; ++i)