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

Function TestEncodeFloat8

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

Source from the content-addressed store, hash-verified

344}
345
346func TestEncodeFloat8(t *testing.T) {
347 tests := []struct {
348 name string
349 input interface{}
350 expected float64
351 }{
352 {"float64 3.14159", float64(3.14159), 3.14159},
353 {"float64 -1e100", float64(-1e100), -1e100},
354 {"float32 2.5", float32(2.5), 2.5},
355 {"int 42", int(42), 42.0},
356 {"int64 1000000", int64(1000000), 1000000.0},
357 }
358
359 for _, tt := range tests {
360 t.Run(tt.name, func(t *testing.T) {
361 result := encodeFloat8(tt.input)
362 if result == nil {
363 t.Fatalf("encodeFloat8(%v) returned nil", tt.input)
364 }
365 if len(result) != 8 {
366 t.Fatalf("encodeFloat8(%v) length = %d, want 8", tt.input, len(result))
367 }
368 bits := binary.BigEndian.Uint64(result)
369 got := math.Float64frombits(bits)
370 if got != tt.expected {
371 t.Errorf("encodeFloat8(%v) = %f, want %f", tt.input, got, tt.expected)
372 }
373 })
374 }
375}
376
377func TestEncodeDate(t *testing.T) {
378 // PostgreSQL epoch is 2000-01-01

Callers

nothing calls this directly

Calls 2

encodeFloat8Function · 0.85
RunMethod · 0.65

Tested by

no test coverage detected