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
|
package byteutil
import "testing"
func TestCountOfByteAndAlphabet(t *testing.T) {
s := []byte("abcdefadfwefasdga")
count := CountOfByte(s)
alphabet := Alphabet(s)
sum := 0
for _, letter := range alphabet {
sum += count[letter]
}
if sum != len(s) {
t.Error("Test failed: TestCountOfByteAndAlphabet")
}
}
func TestSortCountOfByte(t *testing.T) {
s := []byte("cccaaadd")
countList := SortCountOfByte(CountOfByte(s), true)
// fmt.Println(countList)
// if !(countList[0].Count == 3 && (countList[0].Key == 'a' || countList[0].Key == 'c')) {
if !(countList[0].Count == 3 && countList[0].Key == 'a') {
t.Error("Test failed: TestSortCountOfByte")
}
countList = SortCountOfByte(CountOfByte(s), false)
// fmt.Println(countList)
if !(countList[0].Key == 'd' && countList[0].Count == 2) {
t.Error("Test failed: TestSortCountOfByte")
}
}
|