02975a6befa69340be247285b3247f7242ea1e37
[aubio.git] / tests / src / test-cvec.c
1 #include "aubio.h"
2 #include "utils_tests.h"
3
4 int main (void)
5 {
6   aubio_init();
7
8   uint_t i, window_size = 16; // window size
9   cvec_t * complex_vector = new_cvec (window_size); // input buffer
10   uint_t rand_times = 4;
11
12   utils_init_random();
13
14   while (rand_times -- ) {
15     // fill with random phas and norm
16     for ( i = 0; i < complex_vector->length; i++ ) {
17       complex_vector->norm[i] = ( 2. / RAND_MAX * random() - 1. );
18       complex_vector->phas[i] = ( 2. / RAND_MAX * random() - 1. ) * M_PI;
19     }
20     // print the vector
21     cvec_print(complex_vector);
22   }
23
24   // set all vector elements to `0`
25   cvec_norm_zeros(complex_vector);
26   for ( i = 0; i < complex_vector->length; i++ ) {
27     assert( complex_vector->norm[i] == 0. );
28     // assert( complex_vector->phas[i] == 0 );
29   }
30   cvec_print(complex_vector);
31
32   // set all vector elements to `1`
33   cvec_norm_ones(complex_vector);
34   for ( i = 0; i < complex_vector->length; i++ ) {
35     assert( complex_vector->norm[i] == 1. );
36     // assert( complex_vector->phas[i] == 0 );
37   }
38   cvec_print(complex_vector);
39
40   cvec_zeros(complex_vector);
41   cvec_phas_zeros(complex_vector);
42   cvec_norm_zeros(complex_vector);
43   cvec_norm_ones(complex_vector);
44   cvec_phas_ones(complex_vector);
45   cvec_copy(complex_vector, complex_vector);
46
47   // destroy it
48   del_cvec(complex_vector);
49
50   aubio_cleanup();
51
52   return 0;
53 }