1234567891011121314151617181920212223242526272829303132 |
- package main
- import (
- "bufio"
- "bytes"
- "testing"
- )
- func TestCorrupted(t *testing.T) {
- cases := []struct {
- Name string
- Expected int
- Input string
- }{
- {"example", 161, "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"},
- {"intact1", 6, "mul(2,3)"},
- {"corrupt1", 0, "mul(4*"},
- {"corrupt2", 0, "mul(6,9!"},
- {"corrupt3", 0, "?(12,34)"},
- {"corrupt4", 0, "mul ( 2 , 4 )"},
- }
- for _, c := range cases {
- buf := new(bytes.Buffer)
- buf.WriteString(c.Input)
- r := bufio.NewReader(buf)
- actual := process(r)
- if actual != c.Expected {
- t.Errorf("Expected %d; got %d", c.Expected, actual)
- }
- }
- }
|