MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestEncodeFloat4

Function TestEncodeFloat4

server/types_test.go:315–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

313}
314
315func TestEncodeFloat4(t *testing.T) {
316 tests := []struct {
317 name string
318 input interface{}
319 expected float32
320 }{
321 {"float32 3.14", float32(3.14), 3.14},
322 {"float32 -1.5", float32(-1.5), -1.5},
323 {"float64 2.718", float64(2.718), 2.718},
324 {"int 42", int(42), 42.0},
325 {"int32 100", int32(100), 100.0},
326 }
327
328 for _, tt := range tests {
329 t.Run(tt.name, func(t *testing.T) {
330 result := encodeFloat4(tt.input)
331 if result == nil {
332 t.Fatalf("encodeFloat4(%v) returned nil", tt.input)
333 }
334 if len(result) != 4 {
335 t.Fatalf("encodeFloat4(%v) length = %d, want 4", tt.input, len(result))
336 }
337 bits := binary.BigEndian.Uint32(result)
338 got := math.Float32frombits(bits)
339 if got != tt.expected {
340 t.Errorf("encodeFloat4(%v) = %f, want %f", tt.input, got, tt.expected)
341 }
342 })
343 }
344}
345
346func TestEncodeFloat8(t *testing.T) {
347 tests := []struct {

Callers

nothing calls this directly

Calls 2

encodeFloat4Function · 0.85
RunMethod · 0.65

Tested by

no test coverage detected