zigzag_test.go 817 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2011 The Snappy-Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package zigzag
  5. import (
  6. "testing"
  7. )
  8. var testCases = []struct {
  9. u uint64
  10. i int64
  11. }{
  12. {0, +0},
  13. {1, -1},
  14. {2, +1},
  15. {3, -2},
  16. {4, +2},
  17. {5, -3},
  18. {6, +3},
  19. {199, -100},
  20. {200, +100},
  21. {1<<32 - 2, +1<<31 - 1},
  22. {1<<32 - 1, -1<<31 - 0},
  23. {1<<32 + 0, +1<<31 + 0},
  24. {1<<32 + 1, -1<<31 - 1},
  25. {1<<32 + 2, +1<<31 + 1},
  26. {1<<64 - 2, +1<<63 - 1},
  27. {1<<64 - 1, -1<<63 + 0},
  28. }
  29. func TestZigzag(t *testing.T) {
  30. for _, tc := range testCases {
  31. if i := Utoi64(tc.u); i != tc.i {
  32. t.Errorf("uint64 %d to int64: want %d got %d", tc.u, tc.i, i)
  33. }
  34. if u := Itou64(tc.i); u != tc.u {
  35. t.Errorf("int64 %d to uint64: want %d got %d", tc.i, tc.u, u)
  36. }
  37. }
  38. }