You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
714 B

  1. package util
  2. import (
  3. "testing"
  4. )
  5. func TestTTLReadWrite(t *testing.T) {
  6. var tests = []struct {
  7. n int // input
  8. expected int // expected result
  9. }{
  10. {0, -1},
  11. {1, 0},
  12. {1 << 4, 0},
  13. {1 << 6, 1},
  14. {1 << 8, 2},
  15. {1 << 10, 3},
  16. {1 << 12, 4},
  17. {1 << 14, 5},
  18. {1 << 16, 6},
  19. {1 << 18, 7},
  20. {1<<4 + 1, 1},
  21. {1<<6 + 1, 2},
  22. {1<<8 + 1, 3},
  23. {1<<10 + 1, 4},
  24. {1<<12 + 1, 5},
  25. {1<<14 + 1, 6},
  26. {1<<16 + 1, 7},
  27. {1<<18 + 1, 8},
  28. {1<<28 - 1, 12},
  29. {1 << 28, 12},
  30. {1<<28 + 2134, -1},
  31. {1080, 4},
  32. }
  33. for _, tt := range tests {
  34. actual := findChunkPoolIndex(tt.n)
  35. if actual != tt.expected {
  36. t.Errorf("findChunkPoolIndex(%d): expected %d, actual %d", tt.n, tt.expected, actual)
  37. }
  38. }
  39. }