diff options
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r-- | example/ndpiReader.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 207056785..32b7399cd 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -5951,6 +5951,25 @@ void memmemUnitTest(void) { /* *********************************************** */ +void mahalanobisUnitTest() +{ + /* Example based on: https://supplychenmanagement.com/2019/03/06/calculating-mahalanobis-distance/ */ + + const float i_s[3 * 3] = { 0.0482486100061447, -0.00420645518018837, -0.0138921893248235, + -0.00420645518018836, 0.00177288408892603, -0.00649813703331057, + -0.0138921893248235, -0.00649813703331056, 0.066800436339011 }; /* Inverted covar matrix */ + const float u[3] = { 22.8, 180.0, 9.2 }; /* Means vector */ + u_int32_t x[3] = { 26, 167, 12 }; /* Point */ + float md; + + md = ndpi_mahalanobis_distance(x, 3, u, i_s); + /* It is a bit tricky to test float equality on different archs -> loose check. + * md sholud be 1.3753 */ + assert(md >= 1.37 && md <= 1.38); +} + +/* *********************************************** */ + void filterUnitTest() { ndpi_filter* f = ndpi_filter_alloc(); u_int32_t v, i; @@ -6440,6 +6459,7 @@ int main(int argc, char **argv) { strnstrUnitTest(); strncasestrUnitTest(); memmemUnitTest(); + mahalanobisUnitTest(); #endif } |