| 293 | } |
| 294 | |
| 295 | func TestBitArrayFromProto(t *testing.T) { |
| 296 | testCases := []struct { |
| 297 | pbA *tmprotobits.BitArray |
| 298 | resA *BitArray |
| 299 | expErr bool |
| 300 | }{ |
| 301 | 0: {nil, &BitArray{}, false}, |
| 302 | 1: {&tmprotobits.BitArray{}, &BitArray{Elems: []uint64{}}, false}, |
| 303 | |
| 304 | 2: {&tmprotobits.BitArray{Bits: 1, Elems: make([]uint64, 1)}, &BitArray{Bits: 1, Elems: make([]uint64, 1)}, false}, |
| 305 | |
| 306 | 3: {&tmprotobits.BitArray{Bits: -1, Elems: make([]uint64, 1)}, &BitArray{}, true}, |
| 307 | 4: {&tmprotobits.BitArray{Bits: math.MaxInt32 + 1, Elems: make([]uint64, 1)}, &BitArray{}, true}, |
| 308 | 5: {&tmprotobits.BitArray{Bits: 1, Elems: make([]uint64, 2)}, &BitArray{}, true}, |
| 309 | } |
| 310 | |
| 311 | for i, tc := range testCases { |
| 312 | bA := new(BitArray) |
| 313 | err := bA.FromProto(tc.pbA) |
| 314 | if tc.expErr { |
| 315 | assert.Error(t, err, "#%d", i) |
| 316 | assert.Equal(t, tc.resA, bA, "#%d", i) |
| 317 | } else { |
| 318 | assert.NoError(t, err, "#%d", i) |
| 319 | assert.Equal(t, tc.resA, bA, "#%d", i) |
| 320 | } |
| 321 | } |
| 322 | } |