Initial import to Tizen
[profile/ivi/sphinxbase.git] / test / unit / test_logmath / test_log_int8.c
1 #include <logmath.h>
2
3 #include "test_macros.h"
4
5 #define LOG_EPSILON 1500
6
7 int
8 main(int argc, char *argv[])
9 {
10         logmath_t *lmath;
11         int32 rv;
12
13         lmath = logmath_init(1.003, 0, 1);
14         TEST_ASSERT(lmath);
15         printf("log(1e-48) = %d\n", logmath_log(lmath, 1e-48));
16         TEST_EQUAL_LOG(logmath_log(lmath, 1e-48), -36896);
17         printf("exp(log(1e-48)) = %e\n",logmath_exp(lmath, -36896));
18         TEST_EQUAL_FLOAT(logmath_exp(lmath, -36896), 1e-48);
19         printf("log(42) = %d\n", logmath_log(lmath, 42));
20         TEST_EQUAL_LOG(logmath_log(lmath, 42), 1247);
21         printf("exp(log(42)) = %f\n",logmath_exp(lmath, 1247));
22         TEST_EQUAL_FLOAT(logmath_exp(lmath, 1247), 41.9);
23         TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
24                                    logmath_log(lmath, 5e-48)),
25                        logmath_log(lmath, 6e-48));
26         TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
27                                    logmath_log(lmath, 42)), 1247);
28
29         rv = logmath_write(lmath, "tmp.logadd");
30         TEST_EQUAL(rv, 0);
31         logmath_free(lmath);
32         lmath = logmath_read("tmp.logadd");
33         TEST_ASSERT(lmath);
34         TEST_EQUAL_LOG(logmath_log(lmath, 1e-48), -36896);
35         TEST_EQUAL_LOG(logmath_log(lmath, 42), 1247);
36         TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
37                                    logmath_log(lmath, 5e-48)),
38                        logmath_log(lmath, 6e-48));
39         TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
40                                    logmath_log(lmath, 42)), 1247);
41         logmath_free(lmath);
42
43         return 0;
44 }