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

Function TestEncodeNumeric

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

Source from the content-addressed store, hash-verified

883}
884
885func TestEncodeNumeric(t *testing.T) {
886 tests := []struct {
887 name string
888 input duckdb.Decimal
889 expectNdigits uint16
890 expectWeight int16
891 expectSign uint16
892 expectDscale uint16
893 expectDigits []uint16
894 }{
895 {
896 name: "99.99",
897 input: duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(9999)},
898 expectNdigits: 2,
899 expectWeight: 0,
900 expectSign: 0x0000, // NUMERIC_POS
901 expectDscale: 2,
902 expectDigits: []uint16{99, 9900},
903 },
904 {
905 name: "-50.25",
906 input: duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(-5025)},
907 expectNdigits: 2,
908 expectWeight: 0,
909 expectSign: 0x4000, // NUMERIC_NEG
910 expectDscale: 2,
911 expectDigits: []uint16{50, 2500},
912 },
913 {
914 name: "0.00",
915 input: duckdb.Decimal{Width: 10, Scale: 2, Value: big.NewInt(0)},
916 expectNdigits: 0,
917 expectWeight: 0,
918 expectSign: 0x0000,
919 expectDscale: 2,
920 expectDigits: nil,
921 },
922 {
923 name: "12.3456",
924 input: duckdb.Decimal{Width: 8, Scale: 4, Value: big.NewInt(123456)},
925 expectNdigits: 2,
926 expectWeight: 0,
927 expectSign: 0x0000,
928 expectDscale: 4,
929 expectDigits: []uint16{12, 3456},
930 },
931 {
932 name: "0.0001",
933 input: duckdb.Decimal{Width: 8, Scale: 4, Value: big.NewInt(1)},
934 expectNdigits: 1,
935 expectWeight: -1,
936 expectSign: 0x0000,
937 expectDscale: 4,
938 expectDigits: []uint16{1},
939 },
940 {
941 name: "9999.9999",
942 input: duckdb.Decimal{Width: 8, Scale: 4, Value: big.NewInt(99999999)},

Callers

nothing calls this directly

Calls 3

encodeNumericFunction · 0.85
decodeNumericFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected