(t *testing.T)
| 210 | } |
| 211 | |
| 212 | func TestEncodeInt2(t *testing.T) { |
| 213 | tests := []struct { |
| 214 | name string |
| 215 | input interface{} |
| 216 | expected int16 |
| 217 | }{ |
| 218 | {"int 42", int(42), 42}, |
| 219 | {"int -1", int(-1), -1}, |
| 220 | {"int8 127", int8(127), 127}, |
| 221 | {"int16 32767", int16(32767), 32767}, |
| 222 | {"int16 -32768", int16(-32768), -32768}, |
| 223 | {"int32 100", int32(100), 100}, |
| 224 | {"int64 200", int64(200), 200}, |
| 225 | {"uint8 255", uint8(255), 255}, |
| 226 | {"uint16 1000", uint16(1000), 1000}, |
| 227 | {"float32 3.7", float32(3.7), 3}, |
| 228 | {"float64 9.9", float64(9.9), 9}, |
| 229 | } |
| 230 | |
| 231 | for _, tt := range tests { |
| 232 | t.Run(tt.name, func(t *testing.T) { |
| 233 | result := encodeInt2(tt.input) |
| 234 | if result == nil { |
| 235 | t.Fatalf("encodeInt2(%v) returned nil", tt.input) |
| 236 | } |
| 237 | if len(result) != 2 { |
| 238 | t.Fatalf("encodeInt2(%v) length = %d, want 2", tt.input, len(result)) |
| 239 | } |
| 240 | got := int16(binary.BigEndian.Uint16(result)) |
| 241 | if got != tt.expected { |
| 242 | t.Errorf("encodeInt2(%v) = %d, want %d", tt.input, got, tt.expected) |
| 243 | } |
| 244 | }) |
| 245 | } |
| 246 | |
| 247 | // Test unsupported type returns nil |
| 248 | if result := encodeInt2("string"); result != nil { |
| 249 | t.Errorf("encodeInt2(string) should return nil, got %v", result) |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | func TestEncodeInt4(t *testing.T) { |
| 254 | tests := []struct { |
nothing calls this directly
no test coverage detected