1
0

fizzbuzz_fuzz_test.go 661 B

12345678910111213141516171819202122232425262728
  1. package domain
  2. import (
  3. "regexp"
  4. "strings"
  5. "testing"
  6. )
  7. func FuzzFizzBuzz(f *testing.F) {
  8. rx := regexp.MustCompile(strings.Join([]string{
  9. "invalid modulo parameters: ",
  10. "invalid string parameter: empty",
  11. "contains a RFC-3986 reserved character",
  12. }, "|"))
  13. target := func(t *testing.T, int1, int2, limit int, str1, str2 string) {
  14. fbs, err := FizzBuzz(int1, int2, limit, str1, str2)
  15. if err != nil && !rx.MatchString(err.Error()) {
  16. t.Fatalf("Unexpected error: %s", err)
  17. }
  18. if fbs == nil && err == nil {
  19. t.Fatalf("unexpected nil result")
  20. }
  21. if len(fbs) == 0 && err == nil {
  22. t.Fatal("unexpected empty result")
  23. }
  24. }
  25. f.Fuzz(target)
  26. }