Create unit tests for our numerics math library (LIBBN) #3BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: Mandeep KaurTags: C, unit test, math

There are dozens of files in our core LIBBN library. As a core library used by nearly every one of BRL-CAD's tools, testing those functions for correct behavior is important.

References:

  • include/bn.h
  • include/plot3.h
  • include/vmath.h
  • src/libbn/rand.c
  • src/libbu/tests/*.c (note libbu, not libbn for examples)
  • src/libbn/tests/*.c (also many examples, but not as good)

Code:

  • src/libbn/tests/rand.c
  • src/libbn/tests/CMakeLists.txt

This task involves implementing a new unit test for any of LIBBN's source files that do not already have a unit test defined.  The test should run at least 10 public functions if there are multiple functions defined within one of our source files.

Some files, like our mat.c file, have LOTS of functions.  You don't have to test them all!  Just test at least 10 of them and if any prove to be challenging, let us know before you invest more than an hour.  Your unit test(s) must be hooked into our build system and "should" pass.  If you find a genuine bug, let us know (we can create follow-on tasks for any you investigate and fix).  We have lots of existing unit tests to follow as an example.

Submit your new unit test and build system changes as a patch file.  Let us know about any problems or bugs encountered.

Uploaded Work
File name/URLFile sizeDate submitted
more-mat-tests.patch19.0 KBDecember 27 2013 07:32 UTC
Comments
mandaron December 19 2013 14:15 UTCTesting

i have been unit-testing in JAVA. could anyone give me a reference for unit testing in C?

agkphysicson December 27 2013 06:12 UTCTask Claimed

I would like to work on this task.

Sean on December 27 2013 06:47 UTCTask Assigned

This task has been assigned to agkphysics. You have 72 hours to complete this task, good luck!

agkphysicson December 27 2013 07:32 UTCReady for review

The work on this task is ready to be reviewed.

agkphysicson December 27 2013 07:40 UTCNone

I have written tests for 16 more bn_mat functions, but there are some questions I would like to ask before I commit:



  1. Two functions which are trivial are bn_mat_dup() and bn_mat_vtoh_move(). Do these really need a unit test, because they are quite simple functions; and do you want me to remove these simple tests?

  2. All tests pass except two, which are for bn_vec_ae(). I can't find an explanation for this and I think there may be an error in that function itself. When I tested with gdb, the function was consistently returning the same vector z value, irrespective of the input, which seems incorrect to me.

Sean on December 27 2013 07:50 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 27 2013 07:54 UTCgood questions

It's all about code coverage.  Every public function should be tested, no matter how trivial or unimportant it seems.  Bugs often occur in the most simple of functions...


For your tests that don't pass, put a comment in the commit message and with the test that describes what you're observing as failing and why you think it's a bug.  I would be more concerned if you didn't find any bugs.  That's the point of writing unit tests. ;)