quorum_test.go 714 B

123456789101112131415161718192021222324252627282930313233343536
  1. package processor
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestCalculateQuorum(t *testing.T) {
  7. tests := []struct {
  8. have int
  9. want int
  10. }{
  11. {have: 1, want: 1},
  12. {have: 2, want: 2},
  13. {have: 3, want: 3},
  14. {have: 4, want: 3},
  15. {have: 5, want: 4},
  16. {have: 6, want: 5},
  17. {have: 7, want: 5},
  18. {have: 8, want: 6},
  19. {have: 9, want: 7},
  20. {have: 10, want: 7},
  21. {have: 11, want: 8},
  22. {have: 12, want: 9},
  23. {have: 20, want: 14},
  24. {have: 25, want: 17},
  25. {have: 100, want: 67},
  26. }
  27. for _, tt := range tests {
  28. t.Run(fmt.Sprintf("%d have", tt.have), func(t *testing.T) {
  29. if got := CalculateQuorum(tt.have); got != tt.want {
  30. t.Errorf("CalculateQuorum(%d) = %v, want %v", tt.have, got, tt.want)
  31. }
  32. })
  33. }
  34. }