(t *testing.T)
| 681 | } |
| 682 | |
| 683 | func TestDecodeFloat4(t *testing.T) { |
| 684 | tests := []struct { |
| 685 | name string |
| 686 | input []byte |
| 687 | expected float32 |
| 688 | wantErr bool |
| 689 | }{ |
| 690 | {"3.14", func() []byte { b := make([]byte, 4); binary.BigEndian.PutUint32(b, math.Float32bits(3.14)); return b }(), 3.14, false}, |
| 691 | {"zero", []byte{0x00, 0x00, 0x00, 0x00}, 0, false}, |
| 692 | {"-1.5", func() []byte { b := make([]byte, 4); binary.BigEndian.PutUint32(b, math.Float32bits(-1.5)); return b }(), -1.5, false}, |
| 693 | {"insufficient data", []byte{0x00, 0x00}, 0, true}, |
| 694 | {"empty data", []byte{}, 0, true}, |
| 695 | } |
| 696 | |
| 697 | for _, tt := range tests { |
| 698 | t.Run(tt.name, func(t *testing.T) { |
| 699 | result, err := decodeFloat4(tt.input) |
| 700 | if tt.wantErr { |
| 701 | if err == nil { |
| 702 | t.Errorf("decodeFloat4(%v) expected error, got nil", tt.input) |
| 703 | } |
| 704 | return |
| 705 | } |
| 706 | if err != nil { |
| 707 | t.Errorf("decodeFloat4(%v) unexpected error: %v", tt.input, err) |
| 708 | return |
| 709 | } |
| 710 | if result != tt.expected { |
| 711 | t.Errorf("decodeFloat4(%v) = %f, want %f", tt.input, result, tt.expected) |
| 712 | } |
| 713 | }) |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | func TestDecodeFloat8(t *testing.T) { |
| 718 | tests := []struct { |
nothing calls this directly
no test coverage detected