Changeset dfd520b for tests/src


Ignore:
Timestamp:
Dec 21, 2018, 12:44:35 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
9e2c1a1
Parents:
2b1b38a
Message:

[tests] improve test-cvec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/src/test-cvec.c

    r2b1b38a rdfd520b  
    44int main (void)
    55{
    6   uint_t i, window_size = 16; // window size
    7   cvec_t * complex_vector = new_cvec (window_size); // input buffer
    8   uint_t rand_times = 4;
     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);
    99
    10   utils_init_random();
     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);
    1113
    12   while (rand_times -- ) {
    13     // fill with random phas and norm
    14     for ( i = 0; i < complex_vector->length; i++ ) {
    15       complex_vector->norm[i] = ( 2. / RAND_MAX * random() - 1. );
    16       complex_vector->phas[i] = ( 2. / RAND_MAX * random() - 1. ) * M_PI;
    17     }
    18     // print the vector
    19     cvec_print(complex_vector);
     14  // all elements are initialized to 0
     15  for ( i = 0; i < complex_vector->length; i++ ) {
     16    assert( complex_vector->norm[i] == 0. );
     17    assert( complex_vector->phas[i] == 0. );
    2018  }
    2119
    22   // set all vector elements to `0`
     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
     26  cvec_print(complex_vector);
     27
     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
     36  cvec_norm_ones(complex_vector);
     37  for ( i = 0; i < complex_vector->length; i++ ) {
     38    assert( complex_vector->norm[i] == 1. );
     39  }
     40
     41  // set all norm elements to 0
    2342  cvec_norm_zeros(complex_vector);
    2443  for ( i = 0; i < complex_vector->length; i++ ) {
    2544    assert( complex_vector->norm[i] == 0. );
    26     // assert( complex_vector->phas[i] == 0 );
    2745  }
    28   cvec_print(complex_vector);
    2946
    30   // set all vector elements to `1`
    31   cvec_norm_ones(complex_vector);
     47  // set all phas elements to 1
     48  cvec_phas_ones(complex_vector);
    3249  for ( i = 0; i < complex_vector->length; i++ ) {
    33     assert( complex_vector->norm[i] == 1. );
    34     // assert( complex_vector->phas[i] == 0 );
     50    assert( complex_vector->phas[i] == 1. );
    3551  }
    36   cvec_print(complex_vector);
    3752
    38   cvec_zeros(complex_vector);
     53  // set all phas elements to 0
    3954  cvec_phas_zeros(complex_vector);
    40   cvec_norm_zeros(complex_vector);
    41   cvec_norm_ones(complex_vector);
    42   cvec_phas_ones(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
    4361  cvec_copy(complex_vector, complex_vector);
     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);
    4466
    45   // destroy it
    46   del_cvec(complex_vector);
     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);
     75
    4776  return 0;
    4877}
Note: See TracChangeset for help on using the changeset viewer.