示例#1
0
func TestMakeSortedNodes(t *testing.T) {
	str := "112"
	priorityMap := algorithm.MakePriorityMap(str)
	stortedNodes := algorithm.MakeSortedNodes(priorityMap)
	if stortedNodes[0].Value != "2" {
		t.Error("Can not sort Map, sortedNodes[0] is:", stortedNodes[0])
	}
}
示例#2
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)
	}
}
示例#3
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)
	}
}