123456789101112131415161718192021222324252627282930313233 |
- package main
- import (
- "testing"
- )
- func TestCounter(t *testing.T) {
- cases := []struct {
- Name string
- Expected int
- Input string
- }{
- {"No hits", 0, "XXXAAMSMMA"},
- {"One hit", 1, "XXMSAXMASA"},
- {"Two hits", 2, "SAMXMMXMAS"},
- }
- ctr := new(Counter)
- buf := make([]byte, 0, 4)
- for _, c := range cases {
- ctr.cnt = 0
- ctr.Init(buf)
- ctr.Reset()
- for _, e := range c.Input {
- ctr.Event(byte(e))
- }
- actual := ctr.Count()
- if actual != c.Expected {
- t.Errorf("%s: Expected %d hits; got %d", c.Name, c.Expected, actual)
- }
- }
- }
|