Commit c8bfdb8d by Hut

bugfixes

parent f6319bee
...@@ -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;
} }
......
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 testBitVectorFromTomgibaraIgnoresSetFalseAtTheEnd() {
BitVector bitVector = new BitVector(0); BitVector bitVector = new BitVector(0);
assertEquals(0, bitVector.size()); assertEquals(0, bitVector.size());
assertEquals("", bitVector.toString()); assertEquals("", bitVector.toString());
......
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