| 4032 | } |
| 4033 | |
| 4034 | bool arith_test() |
| 4035 | { |
| 4036 | basist::arith_fastbits_f32::init(); |
| 4037 | |
| 4038 | fmt_printf("random bit test\n"); |
| 4039 | |
| 4040 | const uint32_t N = 1000; |
| 4041 | |
| 4042 | // random bit test |
| 4043 | for (uint32_t i = 0; i < N; i++) |
| 4044 | { |
| 4045 | basist::arith::arith_enc enc; |
| 4046 | enc.init(4096); |
| 4047 | |
| 4048 | { |
| 4049 | basisu::rand r; |
| 4050 | r.seed(i + 1); |
| 4051 | uint32_t num_vals = r.irand(1, 20000); |
| 4052 | |
| 4053 | for (uint32_t j = 0; j < num_vals; j++) |
| 4054 | enc.put_bit(r.bit()); |
| 4055 | |
| 4056 | enc.flush(); |
| 4057 | } |
| 4058 | |
| 4059 | { |
| 4060 | basisu::rand r; |
| 4061 | r.seed(i + 1); |
| 4062 | uint32_t num_vals = r.irand(1, 20000); |
| 4063 | |
| 4064 | basist::arith::arith_dec dec; |
| 4065 | dec.init(enc.get_data_buf().get_ptr(), enc.get_data_buf().size()); |
| 4066 | |
| 4067 | for (uint32_t j = 0; j < num_vals; j++) |
| 4068 | { |
| 4069 | uint32_t t = r.bit(); |
| 4070 | |
| 4071 | uint32_t a = dec.get_bit(); |
| 4072 | if (t != a) |
| 4073 | { |
| 4074 | fmt_printf("error!"); |
| 4075 | return false; |
| 4076 | } |
| 4077 | } |
| 4078 | } |
| 4079 | } |
| 4080 | |
| 4081 | fmt_printf("Random bit test OK\n"); |
| 4082 | |
| 4083 | fmt_printf("random bits test\n"); |
| 4084 | |
| 4085 | // random bits test |
| 4086 | for (uint32_t i = 0; i < N; i++) |
| 4087 | { |
| 4088 | basist::arith::arith_enc enc; |
| 4089 | enc.init(4096); |
| 4090 | |
| 4091 | { |
nothing calls this directly
no test coverage detected