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.

35 lines
548 B

  1. package db
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. type foo struct {
  7. V int
  8. }
  9. func TestSliceToSlicePtrs(t *testing.T) {
  10. n := 16
  11. a := make([]foo, n)
  12. for i := 0; i < n; i++ {
  13. a[i] = foo{V: i}
  14. }
  15. b := SliceToSlicePtrs(a).([]*foo)
  16. for i := 0; i < len(a); i++ {
  17. assert.Equal(t, a[i], *b[i])
  18. }
  19. }
  20. func TestSlicePtrsToSlice(t *testing.T) {
  21. n := 16
  22. a := make([]*foo, n)
  23. for i := 0; i < n; i++ {
  24. a[i] = &foo{V: i}
  25. }
  26. b := SlicePtrsToSlice(a).([]foo)
  27. for i := 0; i < len(a); i++ {
  28. assert.Equal(t, *a[i], b[i])
  29. }
  30. }