-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodecTest.cc
More file actions
49 lines (40 loc) · 1.58 KB
/
Copy pathCodecTest.cc
File metadata and controls
49 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "TestUtils.h"
#include <gtest/gtest.h>
#include <random>
#include <src/construct/CsfCodebook.h>
namespace caramel::tests {
TEST(CodecTest, TestSingleCanonicalHuffman) {
std::vector<uint32_t> symbols = {2, 3, 4, 5, 6, 7, 3, 4, 5, 6};
auto huffman_output = canonicalHuffman<uint32_t>(symbols);
for (auto [expected_key, code] : huffman_output.codedict) {
uint32_t actual_key =
canonicalDecode<uint32_t>(code, huffman_output.code_length_counts,
huffman_output.ordered_symbols);
ASSERT_EQ(actual_key, expected_key);
}
}
TEST(CodecTest, TestRandomCanonicalHuffman) {
uint32_t num_iters = 10;
for (uint32_t iter = 0; iter < num_iters; iter++) {
std::vector<uint32_t> symbols = genRandomVector(/* size = */ 30);
auto huffman_output = canonicalHuffman<uint32_t>(symbols);
for (auto [expected_key, code] : huffman_output.codedict) {
uint32_t actual_key =
canonicalDecode<uint32_t>(code, huffman_output.code_length_counts,
huffman_output.ordered_symbols);
ASSERT_EQ(actual_key, expected_key);
}
}
}
TEST(CodecTest, TestRepeatItemCanonicalHuffman) {
std::vector<uint32_t> symbols = {2, 2, 2, 2};
auto huffman_output =
canonicalHuffman<uint32_t>(symbols);
for (auto [expected_key, code] : huffman_output.codedict) {
uint32_t actual_key =
canonicalDecode<uint32_t>(code, huffman_output.code_length_counts,
huffman_output.ordered_symbols);
ASSERT_EQ(actual_key, expected_key);
}
}
} // namespace caramel::tests