2014-04-02 07:57:09 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "svc_enc_golomb.h"
|
|
|
|
#include "macros.h"
|
|
|
|
|
2014-08-11 10:08:49 +02:00
|
|
|
using namespace WelsEnc;
|
2014-04-02 07:57:09 +02:00
|
|
|
|
2014-06-26 03:50:41 +02:00
|
|
|
const double g_kdLog2Factor = 1.0 / log (2.0);
|
2014-04-02 07:57:09 +02:00
|
|
|
|
2014-06-26 03:50:41 +02:00
|
|
|
TEST (UeExpGolombTest, TestBsSizeUeLt256) {
|
2014-04-02 07:57:09 +02:00
|
|
|
uint32_t uiInVal = 0;
|
|
|
|
for (; uiInVal < 256; ++ uiInVal) {
|
2014-06-26 03:50:41 +02:00
|
|
|
const uint32_t uiActVal = BsSizeUE (uiInVal);
|
|
|
|
const int32_t m = static_cast<int32_t> (log ((uiInVal + 1) * 1.0) * g_kdLog2Factor + 1e-6);
|
|
|
|
const uint32_t uiExpVal = (m << 1) + 1;
|
|
|
|
EXPECT_EQ (uiActVal, uiExpVal);
|
2014-04-02 07:57:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 03:50:41 +02:00
|
|
|
TEST (UeExpGolombTest, TestBsSizeUeRangeFrom256To65534) {
|
2014-04-02 07:57:09 +02:00
|
|
|
uint32_t uiInVal = 0x100;
|
|
|
|
for (; uiInVal < 0xFFFF; ++ uiInVal) {
|
2014-06-26 03:50:41 +02:00
|
|
|
const uint32_t uiActVal = BsSizeUE (uiInVal);
|
|
|
|
const int32_t m = static_cast<int32_t> (log ((uiInVal + 1) * 1.0) * g_kdLog2Factor + 1e-6);
|
|
|
|
const uint32_t uiExpVal = (m << 1) + 1;
|
|
|
|
EXPECT_EQ (uiActVal, uiExpVal);
|
2014-04-02 07:57:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 03:50:41 +02:00
|
|
|
TEST (UeExpGolombTest, TestBsSizeUeRangeFrom65535ToPlus256) {
|
2014-04-02 07:57:09 +02:00
|
|
|
uint32_t uiInVal = 0xFFFF;
|
|
|
|
const uint32_t uiCountBase = 256;
|
|
|
|
const uint32_t uiInValEnd = uiInVal + uiCountBase;
|
|
|
|
for (; uiInVal < uiInValEnd; ++ uiInVal) {
|
2014-06-26 03:50:41 +02:00
|
|
|
const uint32_t uiActVal = BsSizeUE (uiInVal);
|
2014-04-02 07:57:09 +02:00
|
|
|
// float precision issue in case use math::log
|
2014-06-26 03:50:41 +02:00
|
|
|
const int32_t m = WELS_LOG2 (1 + uiInVal);
|
|
|
|
const uint32_t uiExpVal = (m << 1) + 1;
|
|
|
|
EXPECT_EQ (uiActVal, uiExpVal);
|
2014-04-02 07:57:09 +02:00
|
|
|
}
|
|
|
|
}
|