Exemple #1
0
func TestShellSort(t *testing.T) {
	var b =[]string{"Sorter", "Orange", "Red", "Tank", "eneny", "X-man", "Angela", "Moon", "Peter", "Linkedin", "Extern"}
	var s ShellSort
	
	a := algorithms.NewStringSlice(b);
	
	for i:=0; i<len(a); i++{
		fmt.Printf("%s ", a[i]);
	}
	fmt.Printf("\n")
	
	s.Sort(a)
	
	for i:=0; i<len(a); i++{
		fmt.Printf("%s ", a[i]);
	}
	fmt.Printf("\n")
	fmt.Printf("a[] is sored? %v\n", s.IsSorted(a))
}
func TestBinarySearchTree2(t *testing.T) {
	var b = []string{"it", "was", "the", "best", "of", "times", "it", "was", "the", "worst", "of", "times",
		"it", "was", "the", "age", "of", "wisdom", "it", "was", "the", "age", "of", "foolishess",
		"it", "was", "the", "epoch", "of", "belief", "it", "was", "the", "epoch", "of", "incredulity",
		"it", "was", "the", "season", "of", "light", "it", "was", "the", "season", "of", "darkness",
		"it", "was", "the", "spring", "of", "hope", "it", "was", "the", "winter", "of", "despair"}

	var st SymbolTable

	a := algorithms.NewStringSlice(b)

	st = &BinarySearchTree{}

	minlen := 1

	for i := 0; i < len(a); i++ {
		word := a[i]
		if len(word.(algorithms.String)) < minlen {
			continue
		}
		if !st.Contains(word) {
			st.Set(word, int(1))
		} else {
			st.Set(word, st.Get(word).(int)+int(1))
		}
	}

	max := algorithms.String(" ")
	st.Set(max, 0)
	iter := st.Keys()
	for iter.HasNext() {
		word := iter.Next().Value.(algorithms.String)
		if st.Get(word).(int) > st.Get(max).(int) {
			max = word
		}
	}

	fmt.Printf("%s %d\n", max, st.Get(max))
}