main_test.go 646 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "bufio"
  4. "bytes"
  5. "testing"
  6. )
  7. func TestCorrupted(t *testing.T) {
  8. cases := []struct {
  9. Name string
  10. Expected int
  11. Input string
  12. }{
  13. {"example", 161, "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"},
  14. {"intact1", 6, "mul(2,3)"},
  15. {"corrupt1", 0, "mul(4*"},
  16. {"corrupt2", 0, "mul(6,9!"},
  17. {"corrupt3", 0, "?(12,34)"},
  18. {"corrupt4", 0, "mul ( 2 , 4 )"},
  19. }
  20. for _, c := range cases {
  21. buf := new(bytes.Buffer)
  22. buf.WriteString(c.Input)
  23. r := bufio.NewReader(buf)
  24. actual := process(r)
  25. if actual != c.Expected {
  26. t.Errorf("Expected %d; got %d", c.Expected, actual)
  27. }
  28. }
  29. }