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

Function TestDecodeNumeric

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

Source from the content-addressed store, hash-verified

1041}
1042
1043func TestDecodeNumeric(t *testing.T) {
1044 tests := []struct {
1045 name string
1046 input duckdb.Decimal // will encode then decode
1047 expected string
1048 }{
1049 {"99.99", duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(9999)}, "99.99"},
1050 {"-50.25", duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(-5025)}, "-50.25"},
1051 {"0.00", duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(0)}, "0.00"},
1052 {"12.3456", duckdb.Decimal{Width: 8, Scale: 4, Value: big.NewInt(123456)}, "12.3456"},
1053 {"0.0001", duckdb.Decimal{Width: 8, Scale: 4, Value: big.NewInt(1)}, "0.0001"},
1054 {"9999.9999", duckdb.Decimal{Width: 8, Scale: 4, Value: big.NewInt(99999999)}, "9999.9999"},
1055 {"10000.00", duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(1000000)}, "10000.00"},
1056 {"1.00", duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(100)}, "1.00"},
1057 }
1058
1059 for _, tt := range tests {
1060 t.Run(tt.name, func(t *testing.T) {
1061 encoded := encodeNumeric(tt.input)
1062 decoded, err := decodeNumeric(encoded)
1063 if err != nil {
1064 t.Fatalf("decodeNumeric failed: %v", err)
1065 }
1066 if decoded != tt.expected {
1067 t.Errorf("decodeNumeric(encodeNumeric(%s)) = %q, want %q", tt.name, decoded, tt.expected)
1068 }
1069 })
1070 }
1071}
1072
1073func TestUBIGINTTypmod(t *testing.T) {
1074 // UBIGINT should map to NUMERIC(20,0) with proper typmod

Callers

nothing calls this directly

Calls 3

encodeNumericFunction · 0.85
decodeNumericFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected