Exemplo n.º 1
0
func TestMakePriorityMap(t *testing.T) {
	str := "1123145512"
	priorityMap := algorithm.MakePriorityMap(str)
	if priorityMap["1"] != 4 {
		t.Error("Can not make a right map, priorityMap[1] =", priorityMap["1"])
	}
}
Exemplo n.º 2
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])
	}
}
Exemplo n.º 3
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)
	}
}
Exemplo n.º 4
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)
	}
}