-- Functionality tests for weighted_statistics extension -- -- Tests core functionality for all weighted statistics functions -- ============================================================================= -- WEIGHTED MEAN TESTS -- ============================================================================= -- Test 1: Basic weighted mean SELECT 'Basic weighted mean' AS test_name, weighted_mean(ARRAY[1.0, 2.0, 3.0], ARRAY[0.1, 0.2, 0.3]) AS result; ERROR: function weighted_mean(numeric[], numeric[]) does not exist LINE 3: weighted_mean(ARRAY[1.0, 2.0, 3.0], ARRAY[0.1, 0.2, 0.3]... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 2: Sparse data weighted mean (sum of weights < 1.0) SELECT 'Sparse weighted mean' AS test_name, weighted_mean(ARRAY[5.0, 10.0], ARRAY[0.2, 0.3]) AS result; ERROR: function weighted_mean(numeric[], numeric[]) does not exist LINE 3: weighted_mean(ARRAY[5.0, 10.0], ARRAY[0.2, 0.3]) AS resu... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 3: Full weight weighted mean (sum = 1.0) SELECT 'Full weight weighted mean' AS test_name, weighted_mean(ARRAY[1.0, 2.0, 3.0], ARRAY[0.2, 0.3, 0.5]) AS result; ERROR: function weighted_mean(numeric[], numeric[]) does not exist LINE 3: weighted_mean(ARRAY[1.0, 2.0, 3.0], ARRAY[0.2, 0.3, 0.5]... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 4: Single value weighted mean SELECT 'Single value weighted mean' AS test_name, weighted_mean(ARRAY[7.5], ARRAY[0.4]) AS result; ERROR: function weighted_mean(numeric[], numeric[]) does not exist LINE 3: weighted_mean(ARRAY[7.5], ARRAY[0.4]) AS result; ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- WEIGHTED QUANTILE TESTS (Simple empirical CDF) -- ============================================================================= -- Test 5: Basic weighted quantiles SELECT 'Basic weighted quantiles' AS test_name, weighted_quantile(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.1, 0.2, 0.3, 0.2, 0.2], ARRAY[0.25, 0.5, 0.75]) AS result; ERROR: function weighted_quantile(numeric[], numeric[], numeric[]) does not exist LINE 3: weighted_quantile(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 6: Sparse data quantiles SELECT 'Sparse weighted quantiles' AS test_name, weighted_quantile(ARRAY[10.0, 20.0], ARRAY[0.3, 0.2], ARRAY[0.25, 0.5, 0.75]) AS result; ERROR: function weighted_quantile(numeric[], numeric[], numeric[]) does not exist LINE 3: weighted_quantile(ARRAY[10.0, 20.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 7: Single quantile SELECT 'Single quantile' AS test_name, weighted_quantile(ARRAY[1.0, 2.0, 3.0], ARRAY[0.3, 0.3, 0.3], ARRAY[0.5]) AS result; ERROR: function weighted_quantile(numeric[], numeric[], numeric[]) does not exist LINE 3: weighted_quantile(ARRAY[1.0, 2.0, 3.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 8: Boundary quantiles SELECT 'Boundary quantiles' AS test_name, weighted_quantile(ARRAY[1.0, 2.0, 3.0, 4.0], ARRAY[0.25, 0.25, 0.25, 0.25], ARRAY[0.0, 1.0]) AS result; ERROR: function weighted_quantile(numeric[], numeric[], numeric[]) does not exist LINE 3: weighted_quantile(ARRAY[1.0, 2.0, 3.0, 4.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- WQUANTILE TESTS (Type 7 / Hyndman-Fan) -- ============================================================================= -- Test 9: Basic wquantile SELECT 'Basic wquantile (Type 7)' AS test_name, wquantile(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.1, 0.2, 0.3, 0.2, 0.2], ARRAY[0.25, 0.5, 0.75]) AS result; ERROR: function wquantile(numeric[], numeric[], numeric[]) does not exist LINE 3: wquantile(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 10: Sparse wquantile SELECT 'Sparse wquantile' AS test_name, wquantile(ARRAY[10.0, 20.0], ARRAY[0.3, 0.2], ARRAY[0.25, 0.5, 0.75]) AS result; ERROR: function wquantile(numeric[], numeric[], numeric[]) does not exist LINE 3: wquantile(ARRAY[10.0, 20.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- WHDQUANTILE TESTS (Harrell-Davis) -- ============================================================================= -- Test 11: Basic whdquantile SELECT 'Basic whdquantile (Harrell-Davis)' AS test_name, whdquantile(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.1, 0.2, 0.3, 0.2, 0.2], ARRAY[0.25, 0.5, 0.75]) AS result; ERROR: function whdquantile(numeric[], numeric[], numeric[]) does not exist LINE 3: whdquantile(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 12: Sparse whdquantile SELECT 'Sparse whdquantile' AS test_name, whdquantile(ARRAY[10.0, 20.0], ARRAY[0.3, 0.2], ARRAY[0.25, 0.5, 0.75]) AS result; ERROR: function whdquantile(numeric[], numeric[], numeric[]) does not exist LINE 3: whdquantile(ARRAY[10.0, 20.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- WEIGHTED MEDIAN TESTS -- ============================================================================= -- Test 13: Basic weighted median SELECT 'Basic weighted median' AS test_name, weighted_median(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.1, 0.2, 0.4, 0.2, 0.1]) AS result; ERROR: function weighted_median(numeric[], numeric[]) does not exist LINE 3: weighted_median(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 14: Sparse weighted median SELECT 'Sparse weighted median' AS test_name, weighted_median(ARRAY[5.0, 15.0], ARRAY[0.3, 0.2]) AS result; ERROR: function weighted_median(numeric[], numeric[]) does not exist LINE 3: weighted_median(ARRAY[5.0, 15.0], ARRAY[0.3, 0.2]) AS re... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- WEIGHTED VARIANCE TESTS -- ============================================================================= -- Test 15: Population variance (ddof=0) SELECT 'Population variance (ddof=0)' AS test_name, weighted_variance(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.2, 0.2, 0.2, 0.2, 0.2], 0) AS result; ERROR: function weighted_variance(numeric[], numeric[], integer) does not exist LINE 3: weighted_variance(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 16: Sample variance (ddof=1) SELECT 'Sample variance (ddof=1)' AS test_name, weighted_variance(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.2, 0.2, 0.2, 0.2, 0.2], 1) AS result; ERROR: function weighted_variance(numeric[], numeric[], integer) does not exist LINE 3: weighted_variance(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 17: Sparse data variance SELECT 'Sparse data variance' AS test_name, weighted_variance(ARRAY[10.0, 20.0], ARRAY[0.3, 0.2], 0) AS result; ERROR: function weighted_variance(numeric[], numeric[], integer) does not exist LINE 3: weighted_variance(ARRAY[10.0, 20.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 18: Default ddof (should be 0) SELECT 'Default ddof variance' AS test_name, weighted_variance(ARRAY[1.0, 2.0, 3.0], ARRAY[0.3, 0.3, 0.3]) AS result; ERROR: function weighted_variance(numeric[], numeric[]) does not exist LINE 3: weighted_variance(ARRAY[1.0, 2.0, 3.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- WEIGHTED STANDARD DEVIATION TESTS -- ============================================================================= -- Test 19: Population std dev (ddof=0) SELECT 'Population std dev (ddof=0)' AS test_name, weighted_std(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.2, 0.2, 0.2, 0.2, 0.2], 0) AS result; ERROR: function weighted_std(numeric[], numeric[], integer) does not exist LINE 3: weighted_std(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 20: Sample std dev (ddof=1) SELECT 'Sample std dev (ddof=1)' AS test_name, weighted_std(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ARRAY[0.2, 0.2, 0.2, 0.2, 0.2], 1) AS result; ERROR: function weighted_std(numeric[], numeric[], integer) does not exist LINE 3: weighted_std(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 21: Sparse data std dev SELECT 'Sparse data std dev' AS test_name, weighted_std(ARRAY[10.0, 20.0], ARRAY[0.3, 0.2], 0) AS result; ERROR: function weighted_std(numeric[], numeric[], integer) does not exist LINE 3: weighted_std(ARRAY[10.0, 20.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 22: Default ddof std dev SELECT 'Default ddof std dev' AS test_name, weighted_std(ARRAY[1.0, 2.0, 3.0], ARRAY[0.3, 0.3, 0.3]) AS result; ERROR: function weighted_std(numeric[], numeric[]) does not exist LINE 3: weighted_std(ARRAY[1.0, 2.0, 3.0], ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- ============================================================================= -- MIXED FUNCTION COMPARISON TESTS -- ============================================================================= -- Test 23: Compare all quantile methods on same data WITH test_data AS ( SELECT ARRAY[1.0, 2.0, 3.0, 4.0, 5.0] AS vals, ARRAY[0.1, 0.2, 0.4, 0.2, 0.1] AS weights, ARRAY[0.5] AS quantiles ) SELECT 'Quantile methods comparison (median)' AS test_name, weighted_quantile(vals, weights, quantiles) AS empirical_cdf, wquantile(vals, weights, quantiles) AS type7, whdquantile(vals, weights, quantiles) AS harrell_davis, ARRAY[weighted_median(vals, weights)] AS median_func FROM test_data; ERROR: function weighted_quantile(numeric[], numeric[], numeric[]) does not exist LINE 9: weighted_quantile(vals, weights, quantiles) AS empirical... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. -- Test 24: Variance and std consistency (std should equal sqrt(variance)) WITH variance_test AS ( SELECT ARRAY[2.0, 4.0, 6.0, 8.0] AS vals, ARRAY[0.25, 0.25, 0.25, 0.25] AS weights ) SELECT 'Variance-std consistency' AS test_name, weighted_variance(vals, weights, 0) AS variance_result, weighted_std(vals, weights, 0) AS std_result, sqrt(weighted_variance(vals, weights, 0)) AS sqrt_variance, abs(weighted_std(vals, weights, 0) - sqrt(weighted_variance(vals, weights, 0))) < 1e-10 AS consistent FROM variance_test; ERROR: function weighted_variance(numeric[], numeric[], integer) does not exist LINE 8: weighted_variance(vals, weights, 0) AS variance_result, ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.