43 lines
616 B
Go
43 lines
616 B
Go
|
package hmm
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestCountNSort(t *testing.T) {
|
||
|
in := []string{"b", "c", "c", "a", "b", "c"}
|
||
|
|
||
|
ch := make(chan string)
|
||
|
go func() {
|
||
|
for _, i := range in {
|
||
|
ch <- i
|
||
|
}
|
||
|
close(ch)
|
||
|
}()
|
||
|
|
||
|
got := CountNSort(ch)
|
||
|
want := Results{
|
||
|
{"a", 1},
|
||
|
{"b", 2},
|
||
|
{"c", 3},
|
||
|
}
|
||
|
|
||
|
if !EqualResults(got, want) {
|
||
|
t.Fatalf("unequal Results: got %v, want %v", got, want)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func EqualResults(a, b Results) bool {
|
||
|
if len(a) != len(b) {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
for i := 0; i < len(a); i++ {
|
||
|
if a[i].Key != b[i].Key {
|
||
|
return false
|
||
|
}
|
||
|
if a[i].Count != b[i].Count {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
return true
|
||
|
}
|