bitmap_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package bitmap
  15. import (
  16. "math"
  17. "testing"
  18. )
  19. func TestUint2IntArray(t *testing.T) {
  20. oneCase := make([]int, 32)
  21. for i := range oneCase {
  22. oneCase[i] = i
  23. }
  24. testCase := []struct {
  25. input uint32
  26. want []int
  27. }{
  28. {24, []int{3, 4}},
  29. {0, []int{}},
  30. {math.MaxUint32, oneCase},
  31. }
  32. for _, tc := range testCase {
  33. real := Uint2IntArray(tc.input)
  34. if !IntSliceEqual(real, tc.want) {
  35. t.Fatalf("want %v, but %v\n", tc.want, real)
  36. }
  37. }
  38. }
  39. func TestIntArray2Uint(t *testing.T) {
  40. oneCase := make([]int, 32)
  41. for i := range oneCase {
  42. oneCase[i] = i
  43. }
  44. testCase := []struct {
  45. want uint32
  46. input []int
  47. }{
  48. {24, []int{3, 4}},
  49. {0, []int{}},
  50. {math.MaxUint32, oneCase},
  51. }
  52. for _, tc := range testCase {
  53. real := IntArray2Uint(tc.input)
  54. if tc.want != real {
  55. t.Fatalf("want %d, but %d\n", tc.want, real)
  56. }
  57. }
  58. }