Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michael A. (Mike) Iovine
p1
Commits
a6d2f914
Commit
a6d2f914
authored
5 years ago
by
Mike Iovine
Browse files
Options
Download
Email Patches
Plain Diff
Update Huffman tests
parent
55059111
master
No related merge requests found
Pipeline
#30561
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
deflated.original
+0
-0
deflated.original
include/inflate.h
+5
-2
include/inflate.h
tests/inflate_test.cpp
+71
-2
tests/inflate_test.cpp
with
76 additions
and
4 deletions
+76
-4
deflated.original
View file @
a6d2f914
No preview for this file type
This diff is collapsed.
Click to expand it.
include/inflate.h
View file @
a6d2f914
...
...
@@ -25,8 +25,11 @@ typedef struct huffman {
/* Reset the position state variable */
void
reset_pos
();
/* Create a Huffman mapping from a sequence of lengths. */
huffman_t
*
make_huffman
(
int
*
lens
,
int
*
alphabet
,
int
n_symbols
);
/*
* Create a Huffman mapping from a sequence of lengths.
* The alphabet used is (0, 1, ..., n_symbols - 1)
*/
huffman_t
*
make_huffman
(
int
*
lens
,
int
n_symbols
);
/* Clean up a heap allocated Huffman map */
void
destroy_huffman
(
huffman_t
*
hf
);
...
...
This diff is collapsed.
Click to expand it.
tests/inflate_test.cpp
View file @
a6d2f914
...
...
@@ -78,10 +78,79 @@ TEST (BufferTests, RevStreamOrderTest) {
ASSERT_EQ
(
get_n_bits
((
char
*
)
buf
,
6
,
true
),
36
);
}
/* Test making a huffman tree from a sequence of lengths */
TEST
(
HuffmanTests
,
TestMakeHuffman
)
{
int
n_symbols
=
8
;
int
lens
[
8
]
=
{
3
,
3
,
3
,
3
,
3
,
2
,
4
,
4
};
huffman_t
*
hf
=
make_huffman
(
lens
,
n_symbols
);
int
bl_counts
[
MAX_LENGTH
+
1
]
=
{
0
,
0
,
1
,
5
,
2
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
/* Check bl_counts */
for
(
int
i
=
0
;
i
<
MAX_LENGTH
+
1
;
i
++
)
{
ASSERT_EQ
(
hf
->
bl_counts
[
i
],
bl_counts
[
i
]);
}
/*
* Check min_codes for entries with non-zero bl_count
* It doesn't really matter what the other entries are.
*/
ASSERT_EQ
(
hf
->
min_codes
[
2
],
0
);
ASSERT_EQ
(
hf
->
min_codes
[
3
],
2
);
ASSERT_EQ
(
hf
->
min_codes
[
4
],
14
);
/* Check that the alphabet arrays were populated correctly. */
ASSERT_EQ
(
hf
->
alphabet
[
2
][
0
],
5
);
for
(
int
i
=
0
;
i
<
5
;
i
++
)
ASSERT_EQ
(
hf
->
alphabet
[
3
][
i
],
i
);
ASSERT_EQ
(
hf
->
alphabet
[
4
][
0
],
6
);
ASSERT_EQ
(
hf
->
alphabet
[
4
][
1
],
7
);
destroy_huffman
(
hf
);
}
/*
* Test that make_huffman does not assign a code to symbols with
* a length of 0.
*/
TEST
(
HuffmanTests
,
TestMakeHuffmanZeroLens
)
{
int
n_symbols
=
8
;
int
lens
[
8
]
=
{
1
,
0
,
2
,
3
,
3
,
0
,
4
,
3
};
huffman_t
*
hf
=
make_huffman
(
lens
,
n_symbols
);
int
bl_counts
[
MAX_LENGTH
+
1
]
=
{
0
,
1
,
1
,
3
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
/* Check bl_counts */
for
(
int
i
=
0
;
i
<
MAX_LENGTH
+
1
;
i
++
)
{
ASSERT_EQ
(
hf
->
bl_counts
[
i
],
bl_counts
[
i
]);
}
/* Check min_codes */
ASSERT_EQ
(
hf
->
min_codes
[
1
],
0
);
ASSERT_EQ
(
hf
->
min_codes
[
2
],
2
);
ASSERT_EQ
(
hf
->
min_codes
[
3
],
6
);
ASSERT_EQ
(
hf
->
min_codes
[
4
],
18
);
/* Check alphabet. */
ASSERT_EQ
(
hf
->
alphabet
[
1
][
0
],
0
);
/* 1 and 5 are not used! (length = 0) */
ASSERT_EQ
(
hf
->
alphabet
[
2
][
0
],
2
);
ASSERT_EQ
(
hf
->
alphabet
[
3
][
0
],
3
);
ASSERT_EQ
(
hf
->
alphabet
[
3
][
1
],
4
);
ASSERT_EQ
(
hf
->
alphabet
[
3
][
2
],
7
);
ASSERT_EQ
(
hf
->
alphabet
[
4
][
0
],
6
);
destroy_huffman
(
hf
);
}
// TODO
TEST
(
HuffmanTests
,
Test
MakeHuffman
)
{
}
TEST
(
HuffmanTests
,
Test
ReadChunk
)
{
TEST
(
HuffmanTests
,
TestReadChunk
)
{
}
}
TEST
(
HuffmanTests
,
TestReadLens
)
{}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help