source: tests/src/test-fvec.c @ 439ba7b

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 439ba7b was 2b1b38a, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] improve test-fvec

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include "aubio.h"
2#include "utils_tests.h"
3
4void assert_fvec_all_equal(fvec_t *vec, smpl_t scalar)
5{
6  uint_t i;
7  for (i = 0; i < vec->length; i++) {
8    assert(vec->data[i] == scalar);
9  }
10}
11
12int main (void)
13{
14  uint_t length = 10;
15  uint_t i;
16
17  fvec_t * vec = new_fvec (length);
18  fvec_t * other_vec = new_fvec (length);
19
20  assert (vec);
21  assert (other_vec);
22
23  // vec->length matches requested size
24  assert(vec->length == length);
25
26  // all elements are initialized to `0.`
27  for ( i = 0; i < vec->length; i++ ) {
28    assert(vec->data[i] == 0.);
29  }
30
31  // all elements can be set to `1.`
32  fvec_ones(vec);
33  assert_fvec_all_equal(vec, 1.);
34
35  // all elements can be set to `0.`
36  fvec_zeros(vec);
37  assert_fvec_all_equal(vec, 0.);
38
39  // each element can be accessed directly
40  for ( i = 0; i < vec->length; i++ ) {
41    vec->data[i] = i;
42    assert(vec->data[i] == i);
43  }
44  fvec_print(vec);
45
46  fvec_set_sample(vec, 3, 2);
47  assert(fvec_get_sample(vec, 2) == 3);
48
49  assert(fvec_get_data(vec) == vec->data);
50
51  // wrong parameters
52  assert(new_fvec(-1) == NULL);
53
54  // copy to an identical size works
55  fvec_copy(vec, other_vec);
56  del_fvec(other_vec);
57
58  // copy to a different size fail
59  other_vec = new_fvec(length + 1);
60  fvec_copy(vec, other_vec);
61  del_fvec(other_vec);
62
63  // copy to a different size fail
64  other_vec = new_fvec(length - 1);
65  fvec_copy(vec, other_vec);
66
67  // now destroys the vector
68  if (vec)
69    del_fvec(vec);
70  if (other_vec)
71    del_fvec(other_vec);
72  return 0;
73}
Note: See TracBrowser for help on using the repository browser.