Bug 1195

Summary: basic-data-calculators-test-suite.cc should use NS_TEST_ASSERT_MSG_EQ_TOL
Product: ns-3 Reporter: Nicola Baldo <nicola>
Component: statsAssignee: Mitch Watrous <watrous>
Status: RESOLVED FIXED    
Severity: normal CC: ns-bugs, tjkopena, tommaso.pecorella
Priority: P5    
Version: ns-3-dev   
Hardware: All   
OS: All   
Attachments: proposed patch

Description Nicola Baldo 2011-06-23 10:01:49 UTC
nicola@pcnbaldo:~/locale/ns-3-dev$ hg tip
changeset:   7313:35a270109ac5
tag:         tip
user:        Mitch Watrous <watrous@u.washington.edu>
date:        Fri Jun 17 15:18:30 2011 -0700
summary:     Bug 1171 - need to generate doxygen automatically for conditionally compiled components


nicola@pcnbaldo:~/locale/ns-3-dev$ ./test.py -s basic-data-calculators -t results.txt 
[SNIP]
FAIL: TestSuite basic-data-calculators
0 of 1 tests passed (0 passed, 0 skipped, 1 failed, 0 crashed, 0 valgrind errors)

nicola@pcnbaldo:~/locale/ns-3-dev$ cat results.txt 
FAIL: Test Suite "basic-data-calculators" (real 0.010 user 0.000 system 0.000)
  PASS: Test Case "Basic Statistical Functions using One Integer" (real 0.000 user 0.000 system 0.000)
  PASS: Test Case "Basic Statistical Functions using Five Integers" (real 0.000 user 0.000 system 0.000)
  FAIL: Test Case "Basic Statistical Functions using Five Double Values" (real 0.000 user 0.000 system 0.000)
    Details:
      Message:   Stddev value wrong
      Condition: calculator.getStddev() (actual) == stddev (limit)
      Actual:    4.96478
      Limit:     4.96478
      File:      ../src/stats/test/basic-data-calculators-test-suite.cc
      Line:      257

The fact is that all the tests macros in basic-data-calculators-test-suite.cc are of the type NS_TEST_ASSERT_MSG_EQ, but they are used to test for equality of double values. From the documentation of NS_TEST_ASSERT_MSG_EQ:

"Do not use this macro if you are comparing floating point numbers
 (float or double) as it is unlikely to do what you expect.  Use 
NS_TEST_ASSERT_MSG_EQ_TOL instead."
Comment 1 Nicola Baldo 2011-06-23 10:02:26 UTC
Created attachment 1171 [details]
proposed patch


The proposed patch changes all macros to NS_TEST_ASSERT_MSG_EQ_TOL. A tolerance of 1e-14 is used, the rationale being that 1) double machine precision is around 1e-16, 2) we should account for additional floating point arithmetic errors of the operations being performed, and 3) it is a more than reasonable accuracy for practical applications.

After applying the patch we get this:

nicola@pcnbaldo:~/locale/ns-3-dev$ ./test.py -s basic-data-calculators -t results.txt 
[SNIP]
PASS: TestSuite basic-data-calculators
1 of 1 tests passed (1 passed, 0 skipped, 0 failed, 0 crashed, 0 valgrind errors)
Comment 2 Tommaso Pecorella 2011-06-23 15:10:08 UTC
I do agree.

+1
Comment 3 Mitch Watrous 2011-06-23 18:15:30 UTC
I applied the patch.  Thanks.  

Bug closed.

ns-3-dev changeset:  998d309a9b3d