source: tests/src/test-cvec.c @ 217ca89

feature/crepe_org
Last change on this file since 217ca89 was dfd520b, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] improve test-cvec

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[332487b]1#include "aubio.h"
[7e35b37]2#include "utils_tests.h"
[4e9101e]3
[158e031]4int main (void)
[7e35b37]5{
[dfd520b]6  uint_t i, window_size = 16;
7  cvec_t * complex_vector = new_cvec(window_size);
8  cvec_t * other_cvector = new_cvec(window_size);
[7e35b37]9
[dfd520b]10  assert(cvec_norm_get_data(complex_vector) == complex_vector->norm);
11  assert(cvec_phas_get_data(complex_vector) == complex_vector->phas);
12  assert(complex_vector->length == window_size / 2 + 1);
13
14  // all elements are initialized to 0
[7e35b37]15  for ( i = 0; i < complex_vector->length; i++ ) {
16    assert( complex_vector->norm[i] == 0. );
[dfd520b]17    assert( complex_vector->phas[i] == 0. );
[7e35b37]18  }
[dfd520b]19
20  cvec_norm_set_sample(complex_vector, 2., 1);
21  assert(cvec_norm_get_sample(complex_vector, 1));
22
23  cvec_phas_set_sample(complex_vector, 2., 1);
24  assert(cvec_phas_get_sample(complex_vector, 1));
25
[7e35b37]26  cvec_print(complex_vector);
[4e9101e]27
[dfd520b]28  // set all norm and phas elements to 0
29  cvec_zeros(complex_vector);
30  for ( i = 0; i < complex_vector->length; i++ ) {
31    assert( complex_vector->norm[i] == 0. );
32    assert( complex_vector->phas[i] == 0. );
33  }
34
35  // set all norm elements to 1
[5d10ac1]36  cvec_norm_ones(complex_vector);
[7e35b37]37  for ( i = 0; i < complex_vector->length; i++ ) {
38    assert( complex_vector->norm[i] == 1. );
39  }
[39a7b26]40
[dfd520b]41  // set all norm elements to 0
[5d10ac1]42  cvec_norm_zeros(complex_vector);
[dfd520b]43  for ( i = 0; i < complex_vector->length; i++ ) {
44    assert( complex_vector->norm[i] == 0. );
45  }
46
47  // set all phas elements to 1
[5d10ac1]48  cvec_phas_ones(complex_vector);
[dfd520b]49  for ( i = 0; i < complex_vector->length; i++ ) {
50    assert( complex_vector->phas[i] == 1. );
51  }
52
53  // set all phas elements to 0
54  cvec_phas_zeros(complex_vector);
55  for ( i = 0; i < complex_vector->length; i++ ) {
56    assert( complex_vector->phas[i] == 0. );
57  }
58
59  cvec_copy(complex_vector, other_cvector);
60  // copy to self
[39a7b26]61  cvec_copy(complex_vector, complex_vector);
[dfd520b]62  // copy to a different size fails
63  del_cvec(other_cvector);
64  other_cvector = new_cvec(window_size + 2);
65  cvec_copy(complex_vector, other_cvector);
66
67  if (complex_vector)
68    del_cvec(complex_vector);
69  if (other_cvector)
70    del_cvec(other_cvector);
71
72  // wrong parameters
73  assert(new_cvec(-1) == NULL);
74  assert(new_cvec(0) == NULL);
[39a7b26]75
[7e35b37]76  return 0;
77}
Note: See TracBrowser for help on using the repository browser.