shuffle_test.go 418 B

123456789101112131415161718192021222324252627
  1. package shuffle
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. type List []string
  7. func (l List) Len() int {
  8. return len(l)
  9. }
  10. func (l List) Swap(i, j int) {
  11. l[i], l[j] = l[j], l[i]
  12. }
  13. func TestShuffle(t *testing.T) {
  14. l := List{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
  15. old := strings.Join(l, "")
  16. Shuffle(l)
  17. new := strings.Join(l, "")
  18. if old == new {
  19. t.Errorf("shuffle error, %s == %s", old, new)
  20. }
  21. t.Log(new)
  22. }