File: count_test.go

package info (click to toggle)
golang-github-shenwei356-util 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 228 kB
  • sloc: makefile: 2
file content (32 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (3)
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")
	}
}