-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhuffman_example_test.go
52 lines (43 loc) · 1.13 KB
/
huffman_example_test.go
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
50
51
52
package huffman_test
import (
"fmt"
"github.com/teeworlds-go/huffman/v2"
)
func ExampleCompress() {
data, err := huffman.Compress([]byte("hello world"))
if err != nil {
panic(err)
}
fmt.Printf("data: %v\n", data)
// Output:
// data: [174 149 19 92 9 87 194 22 177 86 220 218 34 56 185 18 156 168 184 1]
}
func ExampleDecompress() {
data, err := huffman.Decompress([]byte{174, 149, 19, 92, 9, 87, 194, 22, 177, 86, 220, 218, 34, 56, 185, 18, 156, 168, 184, 1})
if err != nil {
panic(err)
}
fmt.Printf("data: %v\n", string(data))
// Output:
// data: hello world
}
func ExampleHuffman_Compress() {
huff := huffman.NewHuffman()
data, err := huff.Compress([]byte("hello world"))
if err != nil {
panic(err)
}
fmt.Printf("data: %v\n", data)
// Output:
// data: [174 149 19 92 9 87 194 22 177 86 220 218 34 56 185 18 156 168 184 1]
}
func ExampleHuffman_Decompress() {
huff := huffman.NewHuffman()
data, err := huff.Decompress([]byte{174, 149, 19, 92, 9, 87, 194, 22, 177, 86, 220, 218, 34, 56, 185, 18, 156, 168, 184, 1})
if err != nil {
panic(err)
}
fmt.Printf("data: %v\n", string(data))
// Output:
// data: hello world
}