(t *testing.T)
| 573 | } |
| 574 | |
| 575 | func TestDecodeInt2(t *testing.T) { |
| 576 | tests := []struct { |
| 577 | name string |
| 578 | input []byte |
| 579 | expected int16 |
| 580 | wantErr bool |
| 581 | }{ |
| 582 | {"positive", []byte{0x00, 0x2A}, 42, false}, |
| 583 | {"negative", []byte{0xFF, 0xFF}, -1, false}, |
| 584 | {"max", []byte{0x7F, 0xFF}, 32767, false}, |
| 585 | {"min", []byte{0x80, 0x00}, -32768, false}, |
| 586 | {"zero", []byte{0x00, 0x00}, 0, false}, |
| 587 | {"insufficient data", []byte{0x00}, 0, true}, |
| 588 | {"empty data", []byte{}, 0, true}, |
| 589 | } |
| 590 | |
| 591 | for _, tt := range tests { |
| 592 | t.Run(tt.name, func(t *testing.T) { |
| 593 | result, err := decodeInt2(tt.input) |
| 594 | if tt.wantErr { |
| 595 | if err == nil { |
| 596 | t.Errorf("decodeInt2(%v) expected error, got nil", tt.input) |
| 597 | } |
| 598 | return |
| 599 | } |
| 600 | if err != nil { |
| 601 | t.Errorf("decodeInt2(%v) unexpected error: %v", tt.input, err) |
| 602 | return |
| 603 | } |
| 604 | if result != tt.expected { |
| 605 | t.Errorf("decodeInt2(%v) = %d, want %d", tt.input, result, tt.expected) |
| 606 | } |
| 607 | }) |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | func TestDecodeInt4(t *testing.T) { |
| 612 | tests := []struct { |
nothing calls this directly
no test coverage detected