7cbbc077bdae3f9143083922120cb3d7afce848a
[opus.git] / libcelt / tests / cwrs32-test.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #define CELT_C 
9 #include "../libcelt/stack_alloc.h"
10 #include "../libcelt/entenc.c"
11 #include "../libcelt/entdec.c"
12 #include "../libcelt/entcode.c"
13 #include "../libcelt/cwrs.c"
14 #include "../libcelt/mathops.c"
15
16 #define NMAX (14)
17 #define KMAX (32767)
18
19 static const int kmax[15]={
20   32767,32767,32767,32767, 1172,
21     238,   95,   53,   36,   27,
22      22,   18,   16,   15,   13
23 };
24
25
26 int main(int _argc,char **_argv){
27   int n;
28   ALLOC_STACK;
29   for(n=2;n<=NMAX;n++){
30     int dk;
31     int k;
32     dk=kmax[n]>7?kmax[n]/7:1;
33     k=1-dk;
34     do{
35       opus_uint32 uu[KMAX+2U];
36       opus_uint32 inc;
37       opus_uint32 nc;
38       opus_uint32 i;
39       k=kmax[n]-dk<k?kmax[n]:k+dk;
40       printf("Testing CWRS with N=%i, K=%i...\n",n,k);
41       nc=ncwrs_urow(n,k,uu);
42       inc=nc/10000;
43       if(inc<1)inc=1;
44       for(i=0;i<nc;i+=inc){
45         opus_uint32 u[KMAX+2U];
46         int           y[NMAX];
47         int           yy[5];
48         opus_uint32 v;
49         opus_uint32 ii;
50         int           kk;
51         int           j;
52         memcpy(u,uu,(k+2U)*sizeof(*u));
53         cwrsi(n,k,i,y,u);
54         /*printf("%6u of %u:",i,nc);
55         for(j=0;j<n;j++)printf(" %+3i",y[j]);
56         printf(" ->");*/
57         ii=icwrs(n,k,&v,y,u);
58         if(ii!=i){
59           fprintf(stderr,"Combination-index mismatch (%lu!=%lu).\n",
60            (long)ii,(long)i);
61           return 1;
62         }
63         if(v!=nc){
64           fprintf(stderr,"Combination count mismatch (%lu!=%lu).\n",
65            (long)v,(long)nc);
66           return 2;
67         }
68 #ifndef SMALL_FOOTPRINT
69         if(n==2){
70           cwrsi2(k,i,yy);
71           for(j=0;j<2;j++)if(yy[j]!=y[j]){
72             fprintf(stderr,"N=2 pulse vector mismatch ({%i,%i}!={%i,%i}).\n",
73              yy[0],yy[1],y[0],y[1]);
74             return 3;
75           }
76           ii=icwrs2(yy,&kk);
77           if(ii!=i){
78             fprintf(stderr,"N=2 combination-index mismatch (%lu!=%lu).\n",
79              (long)ii,(long)i);
80             return 4;
81           }
82           if(kk!=k){
83             fprintf(stderr,"N=2 pulse count mismatch (%i,%i).\n",kk,k);
84             return 5;
85           }
86           v=ncwrs2(k);
87           if(v!=nc){
88             fprintf(stderr,"N=2 combination count mismatch (%lu,%lu).\n",
89              (long)v,(long)nc);
90             return 6;
91           }
92         }
93         else if(n==3){
94           cwrsi3(k,i,yy);
95           for(j=0;j<3;j++)if(yy[j]!=y[j]){
96             fprintf(stderr,"N=3 pulse vector mismatch "
97              "({%i,%i,%i}!={%i,%i,%i}).\n",yy[0],yy[1],yy[2],y[0],y[1],y[2]);
98             return 7;
99           }
100           ii=icwrs3(yy,&kk);
101           if(ii!=i){
102             fprintf(stderr,"N=3 combination-index mismatch (%lu!=%lu).\n",
103              (long)ii,(long)i);
104             return 8;
105           }
106           if(kk!=k){
107             fprintf(stderr,"N=3 pulse count mismatch (%i!=%i).\n",kk,k);
108             return 9;
109           }
110           v=ncwrs3(k);
111           if(v!=nc){
112             fprintf(stderr,"N=3 combination count mismatch (%lu!=%lu).\n",
113              (long)v,(long)nc);
114             return 10;
115           }
116         }
117         else if(n==4){
118           cwrsi4(k,i,yy);
119           for(j=0;j<4;j++)if(yy[j]!=y[j]){
120             fprintf(stderr,"N=4 pulse vector mismatch "
121              "({%i,%i,%i,%i}!={%i,%i,%i,%i}.\n",
122              yy[0],yy[1],yy[2],yy[3],y[0],y[1],y[2],y[3]);
123             return 11;
124           }
125           ii=icwrs4(yy,&kk);
126           if(ii!=i){
127             fprintf(stderr,"N=4 combination-index mismatch (%lu!=%lu).\n",
128              (long)ii,(long)i);
129             return 12;
130           }
131           if(kk!=k){
132             fprintf(stderr,"N=4 pulse count mismatch (%i!=%i).\n",kk,k);
133             return 13;
134           }
135           v=ncwrs4(k);
136           if(v!=nc){
137             fprintf(stderr,"N=4 combination count mismatch (%lu!=%lu).\n",
138              (long)v,(long)nc);
139             return 14;
140           }
141         }
142         else if(n==5){
143           cwrsi5(k,i,yy);
144           for(j=0;j<5;j++)if(yy[j]!=y[j]){
145             fprintf(stderr,"N=5 pulse vector mismatch "
146              "({%i,%i,%i,%i,%i}!={%i,%i,%i,%i,%i}).\n",
147              yy[0],yy[1],yy[2],yy[3],yy[4],y[0],y[1],y[2],y[3],y[4]);
148             return 15;
149           }
150           ii=icwrs5(yy,&kk);
151           if(ii!=i){
152             fprintf(stderr,"N=5 combination-index mismatch (%lu!=%lu).\n",
153              (long)ii,(long)i);
154             return 16;
155           }
156           if(kk!=k){
157             fprintf(stderr,"N=5 pulse count mismatch (%i!=%i).\n",kk,k);
158             return 17;
159           }
160           v=ncwrs5(k);
161           if(v!=nc){
162             fprintf(stderr,"N=5 combination count mismatch (%lu!=%lu).\n",
163              (long)v,(long)nc);
164             return 18;
165           }
166         }
167 #endif /* SMALL_FOOTPRINT */
168
169         /*printf(" %6u\n",i);*/
170       }
171       /*printf("\n");*/
172     }
173     while(k<kmax[n]);
174   }
175   return 0;
176 }