Commit 9ec20f85 authored by Jim Bankoski's avatar Jim Bankoski
Browse files

boolcoder_test

Changed to google style rather than pseudo webm project style

Change-Id: I0e19d57342a1b27b818fe6a5ae9f6bb3710a122a
parent a419f0f2
...@@ -8,32 +8,27 @@ ...@@ -8,32 +8,27 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
extern "C" extern "C" {
{
#include "vp8/encoder/boolhuff.h" #include "vp8/encoder/boolhuff.h"
#include "vp8/decoder/dboolhuff.h" #include "vp8/decoder/dboolhuff.h"
} }
#include <math.h> #include <math.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "third_party/googletest/src/include/gtest/gtest.h" #include "third_party/googletest/src/include/gtest/gtest.h"
#include "vpx/vpx_integer.h"
typedef unsigned char uint8_t; namespace {
namespace
{
const int num_tests = 10; const int num_tests = 10;
class ACMRandom class ACMRandom {
{ public:
public: explicit ACMRandom(int seed) { Reset(seed); }
ACMRandom(int seed) { Reset(seed);}
void Reset(int seed) { srand(seed); } void Reset(int seed) { srand(seed); }
...@@ -45,25 +40,19 @@ public: ...@@ -45,25 +40,19 @@ public:
static int DeterministicSeed(void) { return 0xbaba; } static int DeterministicSeed(void) { return 0xbaba; }
}; };
} } // namespace
TEST(VP8, TestBitIO) TEST(VP8, TestBitIO) {
{
ACMRandom rnd(ACMRandom::DeterministicSeed()); ACMRandom rnd(ACMRandom::DeterministicSeed());
for (int n = 0; n < num_tests; ++n) for (int n = 0; n < num_tests; ++n) {
{ for (int method = 0; method <= 7; ++method) { // we generate various proba
for (int method = 0; method <= 7; ++method)
{ // we generate various proba
const int bits_to_test = 1000; const int bits_to_test = 1000;
uint8_t probas[bits_to_test]; uint8_t probas[bits_to_test];
for (int i = 0; i < bits_to_test; ++i) for (int i = 0; i < bits_to_test; ++i) {
{
const int parity = i & 1; const int parity = i & 1;
probas[i] = probas[i] =
(method == 0) ? 0 : (method == 0) ? 0 : (method == 1) ? 255 :
(method == 1) ? 255 :
(method == 2) ? 128 : (method == 2) ? 128 :
(method == 3) ? rnd.Rand8() : (method == 3) ? rnd.Rand8() :
(method == 4) ? (parity ? 0 : 255) : (method == 4) ? (parity ? 0 : 255) :
...@@ -73,8 +62,7 @@ TEST(VP8, TestBitIO) ...@@ -73,8 +62,7 @@ TEST(VP8, TestBitIO)
(parity ? rnd(64) : 255 - rnd(64)) : (parity ? rnd(64) : 255 - rnd(64)) :
(parity ? rnd(32) : 255 - rnd(32)); (parity ? rnd(32) : 255 - rnd(32));
} }
for (int bit_method = 0; bit_method <= 3; ++bit_method) for (int bit_method = 0; bit_method <= 3; ++bit_method) {
{
const int random_seed = 6432; const int random_seed = 6432;
const int buffer_size = 10000; const int buffer_size = 10000;
ACMRandom bit_rnd(random_seed); ACMRandom bit_rnd(random_seed);
...@@ -83,17 +71,13 @@ TEST(VP8, TestBitIO) ...@@ -83,17 +71,13 @@ TEST(VP8, TestBitIO)
vp8_start_encode(&bw, bw_buffer, bw_buffer + buffer_size); vp8_start_encode(&bw, bw_buffer, bw_buffer + buffer_size);
int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0; int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0;
for (int i = 0; i < bits_to_test; ++i) for (int i = 0; i < bits_to_test; ++i) {
{ if (bit_method == 2) {
if (bit_method == 2)
{
bit = (i & 1); bit = (i & 1);
} } else if (bit_method == 3) {
else if (bit_method == 3)
{
bit = bit_rnd(2); bit = bit_rnd(2);
} }
vp8_encode_bool(&bw, bit, (int) probas[i]); vp8_encode_bool(&bw, bit, static_cast<int>(probas[i]));
} }
vp8_stop_encode(&bw); vp8_stop_encode(&bw);
...@@ -101,22 +85,17 @@ TEST(VP8, TestBitIO) ...@@ -101,22 +85,17 @@ TEST(VP8, TestBitIO)
BOOL_DECODER br; BOOL_DECODER br;
vp8dx_start_decode(&br, bw_buffer, buffer_size); vp8dx_start_decode(&br, bw_buffer, buffer_size);
bit_rnd.Reset(random_seed); bit_rnd.Reset(random_seed);
for (int i = 0; i < bits_to_test; ++i) for (int i = 0; i < bits_to_test; ++i) {
{ if (bit_method == 2) {
if (bit_method == 2)
{
bit = (i & 1); bit = (i & 1);
} } else if (bit_method == 3) {
else if (bit_method == 3)
{
bit = bit_rnd(2); bit = bit_rnd(2);
} }
GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit) GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit)
<< "pos: " << "pos: "<< i << " / " << bits_to_test
<< i << " / " << bits_to_test << " bit_method: " << " bit_method: " << bit_method
<< bit_method << " method: " << method; << " method: " << method;
} }
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment