fizzbuzz_opaque_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package domain_test
  2. import (
  3. "reflect"
  4. "testing"
  5. "code.osinet.fr/fgm/lbc/domain"
  6. )
  7. func TestFizzbuzz(t *testing.T) {
  8. t.Parallel()
  9. const Fizz, Buzz, Both = domain.Fizz, domain.Buzz, domain.Both
  10. type args struct {
  11. int1 int
  12. int2 int
  13. limit int
  14. str1 string
  15. str2 string
  16. }
  17. tests := []struct {
  18. name string
  19. args args
  20. want domain.FizzBuzzes
  21. wantErr bool
  22. }{
  23. {"happy", args{2, 5, 11, Fizz, Buzz}, domain.FizzBuzzes{"1", Fizz, "3", Fizz, Buzz, Fizz, "7", Fizz, "9", Both, "11"}, false},
  24. {"sad modulo 1", args{1, 5, 10, Fizz, Buzz}, nil, true},
  25. {"sad modulo reused", args{5, 5, 10, Fizz, Buzz}, nil, true},
  26. {"sad modulo limit", args{2, 5, 0, Fizz, Buzz}, nil, true},
  27. {"sad empty string", args{2, 5, 11, Fizz, ""}, nil, true},
  28. {"sad reserved string", args{2, 5, 11, Fizz, "/"}, nil, true},
  29. }
  30. for _, tt := range tests {
  31. tt := tt
  32. t.Run(tt.name, func(t *testing.T) {
  33. t.Parallel()
  34. got, err := domain.FizzBuzz(tt.args.int1, tt.args.int2, tt.args.limit, tt.args.str1, tt.args.str2)
  35. if (err != nil) != tt.wantErr {
  36. t.Errorf("FizzBuzz() error = %v, wantErr %v", err, tt.wantErr)
  37. return
  38. }
  39. if !reflect.DeepEqual(got, tt.want) {
  40. t.Errorf("FizzBuzz() got = %v, want %v", got, tt.want)
  41. }
  42. })
  43. }
  44. }