Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
markov
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Patrick Friedel
markov
Commits
c8bfdb8d
Commit
c8bfdb8d
authored
Apr 06, 2018
by
Hut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfixes
parent
f6319bee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
48 deletions
+12
-48
ByteHuffmanCodeBuilderTest.java
src/test/java/markov/huffman/ByteHuffmanCodeBuilderTest.java
+8
-16
DoIUnderstandBitVectorTest.java
src/test/java/markov/huffman/DoIUnderstandBitVectorTest.java
+4
-32
No files found.
src/test/java/markov/huffman/ByteHuffmanCodeBuilderTest.java
View file @
c8bfdb8d
...
@@ -27,11 +27,11 @@ class ByteHuffmanCodeBuilderTest {
...
@@ -27,11 +27,11 @@ class ByteHuffmanCodeBuilderTest {
.
generateCode
(
countMap
,
.
generateCode
(
countMap
,
new
SimpleCountMap
.
MutableInt
.
FrequencySupport
());
new
SimpleCountMap
.
MutableInt
.
FrequencySupport
());
List
<
Boolean
>
result
=
new
ArrayList
<>();
List
<
Boolean
>
result
=
new
ArrayList
<>();
result
.
addAll
(
printVarious
(
code
,
6
));
result
.
addAll
(
encoded
(
code
,
6
));
result
.
addAll
(
printVarious
(
code
,
2
));
result
.
addAll
(
encoded
(
code
,
2
));
result
.
addAll
(
printVarious
(
code
,
1
));
result
.
addAll
(
encoded
(
code
,
1
));
result
.
addAll
(
printVarious
(
code
,
7
));
result
.
addAll
(
encoded
(
code
,
7
));
result
.
addAll
(
printVarious
(
code
,
4
));
result
.
addAll
(
encoded
(
code
,
4
));
System
.
out
.
println
(
result
);
System
.
out
.
println
(
result
);
byte
[]
byteArray
=
Bits
.
asStore
(
Utils
.
fromBitList
(
result
)).
toByteArray
();
byte
[]
byteArray
=
Bits
.
asStore
(
Utils
.
fromBitList
(
result
)).
toByteArray
();
System
.
out
.
println
(
Arrays
.
toString
(
byteArray
));
System
.
out
.
println
(
Arrays
.
toString
(
byteArray
));
...
@@ -41,21 +41,13 @@ class ByteHuffmanCodeBuilderTest {
...
@@ -41,21 +41,13 @@ class ByteHuffmanCodeBuilderTest {
List
<
Boolean
>
list2
=
Bits
.
asStore
(
byteArray2
).
asList
();
List
<
Boolean
>
list2
=
Bits
.
asStore
(
byteArray2
).
asList
();
System
.
out
.
println
(
code
.
decode
(
list2
));
System
.
out
.
println
(
code
.
decode
(
list2
));
System
.
out
.
println
(
code
.
decode
(
result
));
System
.
out
.
println
(
code
.
decode
(
result
));
// result.addAll(printVarious(code, 3));
// result.addAll(printVarious(code, 4));
// result.addAll(printVarious(code, 5));
// result.addAll(printVarious(code, 6));
// result.addAll(printVarious(code, 7));
// System.out.println(result);
// System.out.println(booleanListAsByteArrayToStirng(result));
}
}
private
List
<
Boolean
>
printVarious
(
private
List
<
Boolean
>
encoded
(
HuffmanCode
<
Integer
,
List
<
Boolean
>>
code
,
int
n
)
{
HuffmanCode
<
Integer
,
List
<
Boolean
>>
code
,
int
n
)
{
List
<
Boolean
>
c
=
code
.
encode
(
n
);
List
<
Boolean
>
c
=
code
.
encode
(
n
);
System
.
out
.
println
(
c
);
//
System.out.println(c);
System
.
out
.
println
(
booleanListAsByteArrayToStirng
(
c
));
//
System.out.println(booleanListAsByteArrayToStirng(c));
return
c
;
return
c
;
}
}
...
...
src/test/java/markov/huffman/
HuffmanCodeBuilde
rTest.java
→
src/test/java/markov/huffman/
DoIUnderstandBitVecto
rTest.java
View file @
c8bfdb8d
package
markov
.
huffman
;
package
markov
.
huffman
;
import
com.tomgibara.bits.BitVector
;
import
com.tomgibara.bits.BitVector
;
import
org.junit.jupiter.api.Disabled
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
class
HuffmanCodeBuilderTest
{
class
DoIUnderstandBitVectorTest
{
// @Test
// void testSimple() {
// CountMap<String> counts = new CountMap<>();
// counts.count("a");
// counts.count("a");
// counts.count("b");
// counts.count("c");
// counts.count("c");
// counts.count("c");
// counts.count("d");
// HuffmanCodeBuilder<String, String, String, CountMap.MutableInt> decoder = new <CountMap.MutableInt>HuffmanCodeBuilder<String, String, String, CountMap.MutableInt>(counts,
// () -> new String(),
// p -> p.getCode() + "0",
// p -> p.getCode() + "1",
// mutableInt -> mutableInt.get());
// Map<String, CountMap.MutableInt> frequencies = counts;
// HuffmanCode<String, String> codes = decoder.generateCode();
// assertEquals("10", codes.encode("a"));
// assertEquals("110", codes.encode("b"));
// assertEquals("0", codes.encode("c"));
// assertEquals("111", codes.encode("d"));
//
// assertEquals("a", codes.decode("10"));
// assertEquals("b", codes.decode("110"));
// assertEquals("c", codes.decode("0"));
// assertEquals("d", codes.decode("111"));
// }
//
//
@Disabled
(
"learning test for BitVector, showing why not to use it here"
)
@Test
@Test
public
void
testBitVectorFromTomgibara
()
{
public
void
testBitVectorFromTomgibara
IgnoresSetFalseAtTheEnd
()
{
BitVector
bitVector
=
new
BitVector
(
0
);
BitVector
bitVector
=
new
BitVector
(
0
);
assertEquals
(
0
,
bitVector
.
size
());
assertEquals
(
0
,
bitVector
.
size
());
assertEquals
(
""
,
bitVector
.
toString
());
assertEquals
(
""
,
bitVector
.
toString
());
...
...
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