util_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package chord
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func Test_isEqual(t *testing.T) {
  7. type args struct {
  8. a []byte
  9. b []byte
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. want bool
  15. }{
  16. // TODO: Add test cases.
  17. }
  18. for _, tt := range tests {
  19. t.Run(tt.name, func(t *testing.T) {
  20. if got := isEqual(tt.args.a, tt.args.b); got != tt.want {
  21. t.Errorf("isEqual() = %v, want %v", got, tt.want)
  22. }
  23. })
  24. }
  25. }
  26. func Test_isPowerOfTwo(t *testing.T) {
  27. type args struct {
  28. num int
  29. }
  30. tests := []struct {
  31. name string
  32. args args
  33. want bool
  34. }{
  35. // TODO: Add test cases.
  36. }
  37. for _, tt := range tests {
  38. t.Run(tt.name, func(t *testing.T) {
  39. if got := isPowerOfTwo(tt.args.num); got != tt.want {
  40. t.Errorf("isPowerOfTwo() = %v, want %v", got, tt.want)
  41. }
  42. })
  43. }
  44. }
  45. func Test_randStabilize(t *testing.T) {
  46. type args struct {
  47. min time.Duration
  48. max time.Duration
  49. }
  50. tests := []struct {
  51. name string
  52. args args
  53. want time.Duration
  54. }{
  55. // TODO: Add test cases.
  56. }
  57. for _, tt := range tests {
  58. t.Run(tt.name, func(t *testing.T) {
  59. if got := randStabilize(tt.args.min, tt.args.max); got != tt.want {
  60. t.Errorf("randStabilize() = %v, want %v", got, tt.want)
  61. }
  62. })
  63. }
  64. }
  65. func Test_betweenRightIncl(t *testing.T) {
  66. t.Parallel()
  67. type args struct {
  68. key []byte
  69. a []byte
  70. b []byte
  71. }
  72. tests := []struct {
  73. name string
  74. args args
  75. want bool
  76. }{
  77. {"1", args{[]byte{1, 0, 0, 0}, []byte{0, 0, 0, 0}, []byte{1, 0, 0, 0}}, true},
  78. {"2", args{[]byte{1, 1, 1, 1}, []byte{1, 1, 1, 0}, []byte{1, 1, 1, 1}}, true},
  79. {"3", args{[]byte{1, 1, 1, 1, 1}, []byte{0}, []byte{1, 1, 1, 1}}, false},
  80. {"4", args{[]byte{1, 1, 1, 1, 1}, []byte{0}, []byte{1, 1, 1, 1, 1, 1}}, true},
  81. {
  82. "5",
  83. args{
  84. []byte{4, 40, 171},
  85. []byte{53, 106, 25, 43, 121, 19, 176, 76, 84, 87, 77, 24, 194, 141, 70, 230, 57, 84, 40, 171},
  86. []byte{4, 40, 171},
  87. },
  88. true,
  89. },
  90. }
  91. for _, tt := range tests {
  92. t.Run(tt.name, func(t *testing.T) {
  93. if got := betweenRightIncl(tt.args.key, tt.args.a, tt.args.b); got != tt.want {
  94. t.Errorf("betweenRightIncl(%s) %x in (%x %x] = %v, want %v", tt.name, tt.args.key, tt.args.a, tt.args.b, got, tt.want)
  95. }
  96. })
  97. }
  98. }
  99. func Test_between(t *testing.T) {
  100. type args struct {
  101. key []byte
  102. a []byte
  103. b []byte
  104. }
  105. tests := []struct {
  106. name string
  107. args args
  108. want bool
  109. }{
  110. // TODO: Add test cases.
  111. }
  112. for _, tt := range tests {
  113. t.Run(tt.name, func(t *testing.T) {
  114. if got := between(tt.args.key, tt.args.a, tt.args.b); got != tt.want {
  115. t.Errorf("between() %x in (%x %x]= %v, want %v", tt.args.key, tt.args.a, tt.args.b, got, tt.want)
  116. }
  117. })
  118. }
  119. }