MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestHuffman

Function TestHuffman

compression/huffmancoding_test.go:31–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestHuffman(t *testing.T) {
32 messages := []string{
33 "hello world \U0001F600",
34 "colorless green ideas sleep furiously",
35 "the quick brown fox jumps over the lazy dog",
36 `Lorem ipsum dolor sit amet, consectetur adipiscing elit,
37 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
38 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
39 aliquip ex ea commodo consequat.`,
40 }
41
42 for _, message := range messages {
43 t.Run("huffman: "+message, func(t *testing.T) {
44 tree, _ := compression.HuffTree(SymbolCountOrd(message))
45 codes := make(map[rune][]bool)
46 compression.HuffEncoding(tree, nil, codes)
47 messageCoded := compression.HuffEncode(codes, message)
48 messageHuffDecoded := compression.HuffDecode(tree, tree, messageCoded, "")
49 if messageHuffDecoded != message {
50 t.Errorf("got: %q\nbut expected: %q", messageHuffDecoded, message)
51
52 }
53 })
54 }
55}

Callers

nothing calls this directly

Calls 5

HuffTreeFunction · 0.92
HuffEncodingFunction · 0.92
HuffEncodeFunction · 0.92
HuffDecodeFunction · 0.92
SymbolCountOrdFunction · 0.85

Tested by

no test coverage detected