| 207 | } |
| 208 | |
| 209 | func TestU16EncodeDecodeBig(t *testing.T) { |
| 210 | |
| 211 | n := 102400 |
| 212 | step := 2 |
| 213 | indexes := []int32{} |
| 214 | elts := []uint16{} |
| 215 | |
| 216 | for i := 0; i < n; i += step { |
| 217 | indexes = append(indexes, int32(i)) |
| 218 | elts = append(elts, uint16(i)) |
| 219 | } |
| 220 | |
| 221 | a, err := array.NewU16(indexes, elts) |
| 222 | if err != nil { |
| 223 | t.Errorf("expect no error but: %s", err) |
| 224 | } |
| 225 | |
| 226 | rst, err := proto.Marshal(a) |
| 227 | if err != nil { |
| 228 | t.Errorf("expect no error but: %s", err) |
| 229 | } |
| 230 | |
| 231 | b := &array.U16{} |
| 232 | err = proto.Unmarshal(rst, b) |
| 233 | if err != nil { |
| 234 | t.Errorf("expect no error but: %s", err) |
| 235 | } |
| 236 | |
| 237 | // proto pollute this field |
| 238 | a.XXX_sizecache = 0 |
| 239 | if !reflect.DeepEqual(a, b) { |
| 240 | t.Fatalf("compare: a b: %v", pretty.Diff(a, b)) |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | func BenchmarkU16Get(b *testing.B) { |
| 245 | a, err := array.NewU16([]int32{1, 2, 3}, []uint16{1, 2, 3}) |