endpoint_test.go 737 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package udptransfer
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "sort"
  6. "testing"
  7. )
  8. func Test_insert_delete_rid(t *testing.T) {
  9. var a []uint32
  10. var b = make([]uint32, 0, 1e3)
  11. var uniq = make(map[uint32]int)
  12. // insert into a with random
  13. for i := 0; i < cap(b); i++ {
  14. n := uint32(rand.Int31())
  15. if _, y := uniq[n]; !y {
  16. b = append(b, n)
  17. uniq[n] = 1
  18. }
  19. dups := 1
  20. if i&0xf == 0xf {
  21. dups = 3
  22. }
  23. for j := 0; j < dups; j++ {
  24. if aa := insertRid(a, n); aa != nil {
  25. a = aa
  26. }
  27. }
  28. }
  29. sort.Sort(u32Slice(b))
  30. bStr := fmt.Sprintf("%d", b)
  31. aStr := fmt.Sprintf("%d", a)
  32. assert(aStr == bStr, t, "a!=b")
  33. for i := 0; i < len(b); i++ {
  34. if aa := deleteRid(a, b[i]); aa != nil {
  35. a = aa
  36. }
  37. }
  38. assert(len(a) == 0, t, "a!=0")
  39. }