source: tests/src/test-fvec.c @ 52b0e42

feature/cnn_orgfeature/crepe_org
Last change on this file since 52b0e42 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
RevLine 
[332487b]1#include "aubio.h"
2#include "utils_tests.h"
[4e9101e]3
[2b1b38a]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
[158e031]12int main (void)
[7e35b37]13{
[2b1b38a]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);
[4e9101e]22
[7e35b37]23  // vec->length matches requested size
[2b1b38a]24  assert(vec->length == length);
[c251b80]25
[7e35b37]26  // all elements are initialized to `0.`
27  for ( i = 0; i < vec->length; i++ ) {
28    assert(vec->data[i] == 0.);
29  }
[c251b80]30
[7e35b37]31  // all elements can be set to `1.`
32  fvec_ones(vec);
[2b1b38a]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.);
[7e35b37]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
[2b1b38a]46  fvec_set_sample(vec, 3, 2);
47  assert(fvec_get_sample(vec, 2) == 3);
48
49  assert(fvec_get_data(vec) == vec->data);
[c251b80]50
[2b1b38a]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);
[c251b80]72  return 0;
[4e9101e]73}
Note: See TracBrowser for help on using the repository browser.