Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/celt-0.7.0.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJean-Marc Valin <Jean-Marc.Valin@csiro.au>2008-03-13 09:20:08 +0300
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>2008-03-13 09:20:08 +0300
commit92518982cc3537594b10f40f00e3ba2d606108b3 (patch)
treeeb7423b2ab8c1c8fa8211348733cf5229a5b9863 /tests
parent9d5b4a6f56b1bd896025444d571af76668de4f08 (diff)
Added mathops-test
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/mathops-test.c63
2 files changed, 66 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cf309a3..7d70c99 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,9 +1,9 @@
INCLUDES = -I$(top_srcdir)/libcelt
METASOURCES = AUTO
-TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test
+TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test mathops-test
-noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test
+noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test mathops-test
type_test_SOURCES = type-test.c
ectest_SOURCES = ectest.c
@@ -14,6 +14,7 @@ dft_test_SOURCES = dft-test.c
laplace_test_SOURCES = laplace-test.c
mdct_test_SOURCES = mdct-test.c
rotation_test_SOURCES = rotation-test.c
+mathops_test_SOURCES = mathops-test.c
LDFLAGS = -static
LDADD = $(top_builddir)/libcelt/libcelt.la
diff --git a/tests/mathops-test.c b/tests/mathops-test.c
new file mode 100644
index 0000000..7044913
--- /dev/null
+++ b/tests/mathops-test.c
@@ -0,0 +1,63 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "mathops.h"
+#include <stdio.h>
+#include <math.h>
+
+#ifdef FIXED_POINT
+#define WORD "%d"
+#else
+#define WORD "%f"
+#endif
+
+int ret = 0;
+
+void testdiv()
+{
+ celt_int32_t i;
+ for (i=-327670;i<=327670;i++)
+ {
+ double prod;
+ celt_word32_t val;
+ if (i==0)
+ continue;
+ val = celt_rcp(i);
+#ifdef FIXED_POINT
+ prod = (1./32768./65526.)*val*i;
+#else
+ prod = val*i;
+#endif
+ if (fabs(prod-1) > .001)
+ {
+ fprintf (stderr, "div failed: 1/%d="WORD" (product = %f)\n", i, val, prod);
+ ret = 1;
+ }
+ }
+}
+
+void testsqrt()
+{
+ celt_int32_t i;
+ for (i=1;i<=1000000000;i++)
+ {
+ double ratio;
+ celt_word16_t val;
+ val = celt_sqrt(i);
+ ratio = val/sqrt(i);
+ if (fabs(ratio - 1) > .001 && fabs(val-sqrt(i)) > 2)
+ {
+ fprintf (stderr, "sqrt failed: sqrt(%d)="WORD" (ratio = %f)\n", i, val, ratio);
+ ret = 1;
+ }
+ i+= i>>10;
+ }
+}
+
+int main()
+{
+ testdiv();
+ testsqrt();
+ return 0;
+}