コード例 #1
0
func TestMakeFuffManTree(t *testing.T) {
	str := "111223"
	priorityMap := algorithm.MakePriorityMap(str)
	stortedNodes := algorithm.MakeSortedNodes(priorityMap)
	hfmTree := algorithm.MakeFuffManTree(stortedNodes)
	if hfmTree.Root.Weight != 6 {
		t.Error("Can not make a hfmTree, root is:", hfmTree.Root.LeftChild, hfmTree.Root.RightChild)
	}
}
コード例 #2
0
func TestTraverse(t *testing.T) {
	str := "111223"
	priorityMap := algorithm.MakePriorityMap(str)
	stortedNodes := algorithm.MakeSortedNodes(priorityMap)
	hfmTree := algorithm.MakeFuffManTree(stortedNodes)

	encoding := hfmTree.Encode()
	if encoding["1"] != "1" || encoding["2"] != "01" || encoding["3"] != "00" {
		t.Error("Can not traverse in pre order, first element is:", encoding)
	}
}