| 260 | } |
| 261 | |
| 262 | func TestMatrixJSON(t *testing.T) { |
| 263 | input := []struct { |
| 264 | plain string |
| 265 | value Matrix |
| 266 | }{ |
| 267 | { |
| 268 | plain: `[]`, |
| 269 | value: Matrix{}, |
| 270 | }, |
| 271 | { |
| 272 | plain: samplePairMatrixPlain, |
| 273 | value: samplePairMatrixValue, |
| 274 | }, |
| 275 | } |
| 276 | |
| 277 | for _, test := range input { |
| 278 | b, err := json.Marshal(test.value) |
| 279 | if err != nil { |
| 280 | t.Error(err) |
| 281 | continue |
| 282 | } |
| 283 | |
| 284 | if string(b) != test.plain { |
| 285 | t.Errorf("encoding error: expected %q, got %q", test.plain, b) |
| 286 | continue |
| 287 | } |
| 288 | |
| 289 | var mat Matrix |
| 290 | err = json.Unmarshal(b, &mat) |
| 291 | if err != nil { |
| 292 | t.Error(err) |
| 293 | continue |
| 294 | } |
| 295 | |
| 296 | if !reflect.DeepEqual(mat, test.value) { |
| 297 | t.Errorf("decoding error: expected %v, got %v", test.value, mat) |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | func BenchmarkJSONMarshallingSamplePairMatrix(b *testing.B) { |
| 303 | for i := 0; i < b.N; i++ { |