size_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package validate
  2. import "testing"
  3. func TestMaxSize(t *testing.T) {
  4. type TestCase struct {
  5. Input []int
  6. L int
  7. Err error
  8. }
  9. testCases := []TestCase{
  10. {Input: []int{1, 2, 3, 4}, L: 8},
  11. {Input: []int{1, 2, 3, 4, 5, 6, 7, 8}, L: 8},
  12. {Input: []int{1, 2, 3, 4, 5, 6, 7, 8, 9}, L: 8, Err: ErrTooManyItems},
  13. }
  14. for n, tc := range testCases {
  15. t.Logf("(%d) Testing %q against maximum length of %d", n, tc.Input, tc.L)
  16. f := MaxSize[int](tc.L)
  17. err := f(tc.Input)
  18. if err != tc.Err {
  19. t.Errorf("Expected error %v, got %v", tc.Err, err)
  20. }
  21. }
  22. }
  23. func TestMinSize(t *testing.T) {
  24. type TestCase struct {
  25. Input []int
  26. L int
  27. Err error
  28. }
  29. testCases := []TestCase{
  30. {Input: []int{1, 2, 3, 4}, L: 8, Err: ErrTooFewItems},
  31. {Input: []int{1, 2, 3, 4, 5, 6, 7, 8}, L: 8},
  32. {Input: []int{1, 2, 3, 4, 5, 6, 7, 8, 9}, L: 8},
  33. }
  34. for n, tc := range testCases {
  35. t.Logf("(%d) Testing %q against minimum length of %d", n, tc.Input, tc.L)
  36. f := MinSize[int](tc.L)
  37. err := f(tc.Input)
  38. if err != tc.Err {
  39. t.Errorf("Expected error %v, got %v", tc.Err, err)
  40. }
  41. }
  42. }