Unit tests for bitexact_cos() and bitexact_log2tan().
authorGregory Maxwell <greg@xiph.org>
Mon, 8 Aug 2011 02:42:56 +0000 (22:42 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Mon, 8 Aug 2011 15:34:03 +0000 (11:34 -0400)
libcelt/tests/mathops-test.c

index 56ac5b7..d15fceb 100644 (file)
@@ -3,7 +3,12 @@
 #endif
 
 #include "mathops.c"
+#include "entenc.c"
+#include "entdec.c"
 #include "entcode.c"
+#include "bands.c"
+#include "vq.c"
+#include "cwrs.c"
 #include <stdio.h>
 #include <math.h>
 
@@ -57,6 +62,59 @@ void testsqrt(void)
    }
 }
 
+void testbitexactcos(void)
+{
+   int i;
+   opus_int32 min_d,max_d,last,chk;
+   chk=max_d=0;
+   last=min_d=32767;
+   for(i=0;i<16385;i++)
+   {
+      opus_int32 d;
+      opus_int32 q=bitexact_cos(i);
+      chk ^= q*i;
+      d = last - q;
+      if (d>max_d)max_d=d;
+      if (d<min_d)min_d=d;
+      last = q;
+   }
+   if ((chk!=91017006)||(max_d!=5)||(min_d!=0)||(bitexact_cos(0)!=32767)||
+       (bitexact_cos(16384)!=1)||(bitexact_cos(8192)!=23171))
+   {
+      fprintf (stderr, "bitexact_cos failed\n");
+      ret = 1;
+   }
+}
+
+void testbitexactlog2tan(void)
+{
+   int i,fail;
+   opus_int32 min_d,max_d,last,chk;
+   fail=chk=max_d=0;
+   last=min_d=30690;
+   for(i=0;i<8193;i++)
+   {
+      opus_int32 d;
+      opus_int32 mid=bitexact_cos(i);
+      opus_int32 side=bitexact_cos(16384-i);
+      opus_int32 q=bitexact_log2tan(mid,side);
+      chk ^= q*i;
+      d = last - q;
+      if (q!=-1*bitexact_log2tan(side,mid))
+        fail = 1;
+      if (d>max_d)max_d=d;
+      if (d<min_d)min_d=d;
+      last = q;
+   }
+   if ((chk!=16578548)||(max_d!=3219)||(min_d!=-2)||fail||
+       (bitexact_log2tan(32767,1)!=30690)||(bitexact_log2tan(30274,12540)!=2611)||
+       (bitexact_log2tan(23171,23171)!=0))
+   {
+      fprintf (stderr, "bitexact_log2tan failed\n");
+      ret = 1;
+   }
+}
+
 #ifndef FIXED_POINT
 void testlog2(void)
 {
@@ -160,6 +218,8 @@ void testilog2(void)
 
 int main(void)
 {
+   testbitexactcos();
+   testbitexactlog2tan();
    testdiv();
    testsqrt();
    testlog2();