shithub: aubio

Download patch

ref: 9e2c1a1639ad90dbd0596b94bdc8e64416723926
parent: dfd520b115ce0c9ee9d64ec6029d8dd0d0bee1ba
author: Paul Brossier <piem@piem.org>
date: Fri Dec 21 07:44:46 EST 2018

[tests] improve test-lvec

--- a/tests/src/test-lvec.c
+++ b/tests/src/test-lvec.c
@@ -1,18 +1,47 @@
 #include "aubio.h"
 #include "utils_tests.h"
 
+void assert_lvec_all_equal(lvec_t *vec, lsmp_t scalar)
+{
+  uint_t i;
+  for (i = 0; i < vec->length; i++) {
+    assert(vec->data[i] == scalar);
+  }
+}
+
 int main (void)
 {
-  uint_t win_s = 32; // window size
-  lvec_t * sp = new_lvec (win_s); // input buffer
-  lvec_set_sample (sp, 2./3., 0);
-  PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (sp, 0));
-  lvec_print (sp);
-  lvec_ones (sp);
-  lvec_print (sp);
-  lvec_set_all (sp, 3./5.);
-  lvec_print (sp);
-  del_lvec(sp);
+  uint_t length = 32; // window size
+
+  lvec_t * vec = new_lvec (length); // input buffer
+
+  assert(vec);
+
+  assert(vec->length == length);
+
+  lvec_set_sample (vec, 3., 0);
+  assert(lvec_get_sample(vec, 0) == 3.);
+
+  assert(lvec_get_data(vec) == vec->data);
+
+  lvec_print (vec);
+  // note AUBIO_LSMP_FMT can be used to print lsmp_t
+  PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (vec, 0));
+
+  lvec_set_all (vec, 2.);
+  assert_lvec_all_equal(vec, 2.);
+
+  lvec_ones (vec);
+  assert_lvec_all_equal(vec, 1.);
+
+  lvec_zeros (vec);
+  assert_lvec_all_equal(vec, 0.);
+
+  del_lvec(vec);
+
+  // wrong parameters
+  assert(new_lvec(0) == NULL);
+  assert(new_lvec(-1) == NULL);
+
   return 0;
 }
-