Commit graph

21 commits

Author SHA1 Message Date
Dag-Erling Smørgrav
01ffa275ad Increase test coverage for cryb_mpi_add_abs(). 2017-02-19 17:29:07 +01:00
Dag-Erling Smørgrav
894cc207b9 Additional tests for cryb_mpi_{add,sub}_abs().
These tests reveal that both functions assume that the target is initially positive zero if it is not identical with one of the operands, and fail in various ways if it is not, or if it is uninitialized.
2017-02-19 17:11:02 +01:00
Dag-Erling Smørgrav
ae7f1e909e Rework t_compare_mpi() to improve diagnostics. 2017-02-19 14:38:24 +01:00
Dag-Erling Smørgrav
856571a06d Implement a soft assert for unit tests.
Unlike assert(3), which uses abort(3), this has no other side effects (before raising SIGABRT) than an fprintf() call.  The test framework will catch the SIGABRT, report that the test case failed, and proceed with the next case.
2016-11-14 13:00:16 +01:00
Dag-Erling Smørgrav
a36c6ba31c Add tests for each library's cryb_foo_version() function.
This may seem stupid, but I've found bugs in the past which would have been caught by unit tests which I didn't write because they seemed stupid.
2016-09-17 16:14:00 +02:00
Dag-Erling Smørgrav
e276f2b407 Ensure that we always have off_t and ssize_t in scope.
POSIX requires <stdio.h> and <unistd.h> to define off_t and ssize_t like <sys/types.h> does, but not all platforms respect that.  Play it safe by always including <sys/types.h>.
2016-09-15 10:15:00 +02:00
Dag-Erling Smørgrav
401465d8ea Move main() from libcryb-test to the test program.
Instead of having libcryb-test provide main() and assume that the test program defines t_prepare() and t_cleanup(), have libcryb-test provide a t_main() function which the test program calls with pointers to its prepare and cleanup functions.
2016-03-15 14:29:44 +01:00
Dag-Erling Smørgrav
454603d4f1 Add <unistd.h> to more files. FreeBSD's namespace pollution hides these
errors.
2015-10-12 11:45:26 +00:00
Dag-Erling Smørgrav
f8ebdbc14d Move the test framework into its own subdirectory 2015-10-04 07:49:48 +00:00
Dag-Erling Smørgrav
cddb6c0e02 Rewrite the zero shortcut tests to avoid dropping a const qualifier. 2014-12-30 20:03:58 +00:00
Dag-Erling Smørgrav
3904e809b2 Add two test cases for shortcut logic used when one operand is zero and
the other is also the target.
2014-12-30 19:57:07 +00:00
Dag-Erling Smørgrav
241f524238 Fix a bogus t_malloc_fail in one of the mpi_add_abs() tests.
Add several subtraction test cases and modify some others to better
exercise the carry logic, which is far more complex for subtraction than
for addition.

Add test cases where the target is the same MPI as one or both operands.
2014-12-30 19:48:57 +00:00
Dag-Erling Smørgrav
8d0e24dee7 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.
2014-12-30 17:00:56 +00:00
Dag-Erling Smørgrav
f18b915b67 Fix the "x = a + b" allocation failure test. Since a and b were
equal, mpi_sub_abs() would return early and the test would never
exercise the mpi_grow() call which is intended to fail.
2014-12-30 16:46:44 +00:00
Dag-Erling Smørgrav
2027ce33e7 Add tests for the off-by-one bug we just fixed in mpi_cmp_abs(). 2014-12-30 16:38:47 +00:00
Dag-Erling Smørgrav
e21452d0c7 Add a few tests for subtraction. They're not particularly well thought
out, because currently subtraction does not work at all, but they work
well enough in the sense that they fail with the current implementation.
2014-12-30 11:19:02 +00:00
Dag-Erling Smørgrav
03867777c6 Add numerous tests, mostly for allocation failures and edge conditions.
Add a t_compare_mpi() predicate which checks that two MPIs have the same
value (but not necessarily the exact same representation).
Clean up and improve existing tests.
2014-12-29 23:54:02 +00:00
Dag-Erling Smørgrav
1fbf2cf156 It appears that gcc does not accept partial struct initialization. Add
a CRYB_MPI_ZERO macro that expands to an all-zeroes initializer.
2014-10-30 12:46:01 +00:00
Dag-Erling Smørgrav
3be915b8d7 Previous commit was incomplete. Add missing prototypes and a test case. 2014-08-14 18:42:52 +00:00
Dag-Erling Smørgrav
885c586ce9 Add a test function for comparison operators (but no test cases yet).
Consistently destroy MPIs after use.
2014-08-14 18:26:06 +00:00
Dag-Erling Smørgrav
be31515f5e Start of a multiple-precision integer arithmetic library. 2014-08-12 07:30:31 +00:00