- Timestamp:
- Dec 21, 2018, 12:44:22 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- dfd520b
- Parents:
- 8e76c71
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/src/test-fvec.c
r8e76c71 r2b1b38a 2 2 #include "utils_tests.h" 3 3 4 void 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 4 12 int main (void) 5 13 { 6 uint_t vec_size = 10, i; 7 fvec_t * vec = new_fvec (vec_size); 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); 8 22 9 23 // vec->length matches requested size 10 assert(vec->length == vec_size);24 assert(vec->length == length); 11 25 12 26 // all elements are initialized to `0.` … … 15 29 } 16 30 31 // all elements can be set to `1.` 32 fvec_ones(vec); 33 assert_fvec_all_equal(vec, 1.); 34 17 35 // all elements can be set to `0.` 18 36 fvec_zeros(vec); 19 for ( i = 0; i < vec->length; i++ ) { 20 assert(vec->data[i] == 0.); 21 } 22 fvec_print(vec); 23 24 // all elements can be set to `1.` 25 fvec_ones(vec); 26 for ( i = 0; i < vec->length; i++ ) { 27 assert(vec->data[i] == 1.); 28 } 29 fvec_print(vec); 37 assert_fvec_all_equal(vec, 0.); 30 38 31 39 // each element can be accessed directly … … 36 44 fvec_print(vec); 37 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 38 67 // now destroys the vector 39 del_fvec(vec); 40 68 if (vec) 69 del_fvec(vec); 70 if (other_vec) 71 del_fvec(other_vec); 41 72 return 0; 42 73 } 43
Note: See TracChangeset
for help on using the changeset viewer.