cursor_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package service
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. model "go-common/app/interface/main/reply/model/reply"
  7. )
  8. func TestRemove(t *testing.T) {
  9. cases := []struct {
  10. inputIds []int64
  11. id int64
  12. expected []int64
  13. }{
  14. {
  15. inputIds: []int64{5, 3, 2, 1},
  16. id: 6,
  17. expected: []int64{5, 3, 2, 1},
  18. },
  19. {
  20. inputIds: []int64{6, 5, 3, 2, 1},
  21. id: 6,
  22. expected: []int64{5, 3, 2, 1},
  23. },
  24. {
  25. inputIds: []int64{5, 3, 1, 6, 1, 2},
  26. id: 1,
  27. expected: []int64{5, 3, 6, 2},
  28. },
  29. }
  30. for _, c := range cases {
  31. t.Run("", func(t *testing.T) {
  32. got := Remove(c.inputIds, c.id)
  33. if !reflect.DeepEqual(c.expected, got) {
  34. t.Errorf("err sort, want %v, got %v", c.expected, got)
  35. }
  36. })
  37. }
  38. }
  39. func TestUnique(t *testing.T) {
  40. cases := []struct {
  41. inputIds []int64
  42. expected []int64
  43. }{
  44. {
  45. inputIds: []int64{1, 2, 1, 2, 3, 43},
  46. expected: []int64{1, 2, 3, 43},
  47. },
  48. }
  49. for _, c := range cases {
  50. t.Run("", func(t *testing.T) {
  51. got := model.SortArr(Unique(c.inputIds), model.OrderASC)
  52. if !reflect.DeepEqual(c.expected, got) {
  53. t.Errorf("err sort, want %v, got %v", c.expected, got)
  54. }
  55. })
  56. }
  57. }
  58. func TestNewCursorByReplyID(t *testing.T) {
  59. s := &Service{}
  60. s.NewCursorByReplyID(context.Background(), 1123, int8(1), 112, 20, model.OrderDESC)
  61. }
  62. func TestGetRootReplyListByCursor(t *testing.T) {
  63. s := &Service{}
  64. s.GetRootReplyListByCursor(context.Background(), &model.CursorParams{})
  65. }
  66. func TestInsertInto(t *testing.T) {
  67. cases := []struct {
  68. inputIds []int64
  69. id int64
  70. size int
  71. comp model.Comp
  72. expected []int64
  73. }{
  74. {
  75. inputIds: []int64{},
  76. id: 100,
  77. size: 5,
  78. expected: []int64{100},
  79. comp: model.OrderDESC,
  80. },
  81. {
  82. inputIds: []int64{1, 2, 3, 5},
  83. size: 5,
  84. id: 4,
  85. expected: []int64{1, 2, 3, 4, 5},
  86. comp: model.OrderASC,
  87. },
  88. {
  89. inputIds: []int64{2, 5, 1, 3},
  90. size: 5,
  91. id: 4,
  92. expected: []int64{5, 4, 3, 2, 1},
  93. comp: model.OrderDESC,
  94. },
  95. {
  96. inputIds: []int64{1, 2, 3, 5},
  97. size: 5,
  98. id: 4,
  99. expected: []int64{5, 4, 3, 2, 1},
  100. comp: model.OrderDESC,
  101. },
  102. {
  103. inputIds: []int64{1, 2, 3, 4, 5},
  104. size: 5,
  105. id: 4,
  106. expected: []int64{1, 2, 3, 4, 5},
  107. comp: model.OrderDESC,
  108. },
  109. {
  110. inputIds: []int64{1, 2, 3, 4, 5},
  111. size: 5,
  112. id: 4,
  113. expected: []int64{1, 2, 3, 4, 5},
  114. comp: model.OrderASC,
  115. },
  116. {
  117. inputIds: []int64{5, 4, 3, 1},
  118. id: 2,
  119. size: 5,
  120. expected: []int64{5, 4, 3, 2, 1},
  121. comp: model.OrderDESC,
  122. },
  123. {
  124. inputIds: []int64{5},
  125. id: 4,
  126. size: 2,
  127. expected: []int64{5, 4},
  128. comp: model.OrderDESC,
  129. },
  130. {
  131. inputIds: []int64{5},
  132. id: 4,
  133. size: 2,
  134. expected: []int64{4, 5},
  135. comp: model.OrderASC,
  136. },
  137. {
  138. inputIds: []int64{5},
  139. id: 4,
  140. size: 1,
  141. expected: []int64{5},
  142. comp: model.OrderDESC,
  143. },
  144. }
  145. for _, c := range cases {
  146. t.Run("", func(t *testing.T) {
  147. got := InsertInto(c.inputIds, c.id, c.size, c.comp)
  148. if !reflect.DeepEqual(c.expected, got) {
  149. t.Errorf("err sorted insert, want %v, got %v", c.expected, got)
  150. }
  151. })
  152. }
  153. }