Permalink
Browse files

Added basic regression tests for all supported data types.

  • Loading branch information...
tvondra committed Apr 3, 2012
1 parent a57b428 commit 754d1cccdfdc45a5e3dee2238a2811f23a5ce608
Showing with 284 additions and 0 deletions.
  1. +4 −0 Makefile
  2. +223 −0 test/expected/base.out
  3. +57 −0 test/sql/base.sql
View
@@ -7,6 +7,10 @@ MODULES = quantile
CFLAGS=`pg_config --includedir-server`
TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
View
@@ -0,0 +1,223 @@
BEGIN;
CREATE EXTENSION quantile;
-- int
SELECT quantile(x, 0.5) FROM generate_series(1,1000) s(x);
quantile
----------
500
(1 row)
SELECT quantile(x, 0.1) FROM generate_series(1,1000) s(x);
quantile
----------
100
(1 row)
SELECT quantile(x, 0) FROM generate_series(1,1000) s(x);
quantile
----------
1
(1 row)
SELECT quantile(x, 1) FROM generate_series(1,1000) s(x);
quantile
----------
1000
(1 row)
SELECT quantile(x, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
quantile
----------
{500}
(1 row)
SELECT quantile(x, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
quantile
----------
{100}
(1 row)
SELECT quantile(x, ARRAY[0]) FROM generate_series(1,1000) s(x);
quantile
----------
{1}
(1 row)
SELECT quantile(x, ARRAY[1]) FROM generate_series(1,1000) s(x);
quantile
----------
{1000}
(1 row)
SELECT quantile(x, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
quantile
----------------------
{1,100,500,750,1000}
(1 row)
-- bigint
SELECT quantile(x::bigint, 0.5) FROM generate_series(1,1000) s(x);
quantile
----------
500
(1 row)
SELECT quantile(x::bigint, 0.1) FROM generate_series(1,1000) s(x);
quantile
----------
100
(1 row)
SELECT quantile(x::bigint, 0) FROM generate_series(1,1000) s(x);
quantile
----------
1
(1 row)
SELECT quantile(x::bigint, 1) FROM generate_series(1,1000) s(x);
quantile
----------
1000
(1 row)
SELECT quantile(x::bigint, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
quantile
----------
{500}
(1 row)
SELECT quantile(x::bigint, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
quantile
----------
{100}
(1 row)
SELECT quantile(x::bigint, ARRAY[0]) FROM generate_series(1,1000) s(x);
quantile
----------
{1}
(1 row)
SELECT quantile(x::bigint, ARRAY[1]) FROM generate_series(1,1000) s(x);
quantile
----------
{1000}
(1 row)
SELECT quantile(x::bigint, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
quantile
----------------------
{1,100,500,750,1000}
(1 row)
-- double precision
SELECT quantile(x::double precision, 0.5) FROM generate_series(1,1000) s(x);
quantile
----------
500
(1 row)
SELECT quantile(x::double precision, 0.1) FROM generate_series(1,1000) s(x);
quantile
----------
100
(1 row)
SELECT quantile(x::double precision, 0) FROM generate_series(1,1000) s(x);
quantile
----------
1
(1 row)
SELECT quantile(x::double precision, 1) FROM generate_series(1,1000) s(x);
quantile
----------
1000
(1 row)
SELECT quantile(x::double precision, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
quantile
----------
{500}
(1 row)
SELECT quantile(x::double precision, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
quantile
----------
{100}
(1 row)
SELECT quantile(x::double precision, ARRAY[0]) FROM generate_series(1,1000) s(x);
quantile
----------
{1}
(1 row)
SELECT quantile(x::double precision, ARRAY[1]) FROM generate_series(1,1000) s(x);
quantile
----------
{1000}
(1 row)
SELECT quantile(x::double precision, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
quantile
----------------------
{1,100,500,750,1000}
(1 row)
-- numeric
SELECT quantile(x::numeric, 0.5) FROM generate_series(1,1000) s(x);
quantile
----------
500
(1 row)
SELECT quantile(x::numeric, 0.1) FROM generate_series(1,1000) s(x);
quantile
----------
100
(1 row)
SELECT quantile(x::numeric, 0) FROM generate_series(1,1000) s(x);
quantile
----------
1
(1 row)
SELECT quantile(x::numeric, 1) FROM generate_series(1,1000) s(x);
quantile
----------
1000
(1 row)
SELECT quantile(x::numeric, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
quantile
----------
{500}
(1 row)
SELECT quantile(x::numeric, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
quantile
----------
{100}
(1 row)
SELECT quantile(x::numeric, ARRAY[0]) FROM generate_series(1,1000) s(x);
quantile
----------
{1}
(1 row)
SELECT quantile(x::numeric, ARRAY[1]) FROM generate_series(1,1000) s(x);
quantile
----------
{1000}
(1 row)
SELECT quantile(x::numeric, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
quantile
----------------------
{1,100,500,750,1000}
(1 row)
ROLLBACK;
View
@@ -0,0 +1,57 @@
BEGIN;
CREATE EXTENSION quantile;
-- int
SELECT quantile(x, 0.5) FROM generate_series(1,1000) s(x);
SELECT quantile(x, 0.1) FROM generate_series(1,1000) s(x);
SELECT quantile(x, 0) FROM generate_series(1,1000) s(x);
SELECT quantile(x, 1) FROM generate_series(1,1000) s(x);
SELECT quantile(x, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
SELECT quantile(x, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x, ARRAY[0]) FROM generate_series(1,1000) s(x);
SELECT quantile(x, ARRAY[1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
-- bigint
SELECT quantile(x::bigint, 0.5) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, 0.1) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, 0) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, 1) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, ARRAY[0]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, ARRAY[1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::bigint, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
-- double precision
SELECT quantile(x::double precision, 0.5) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, 0.1) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, 0) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, 1) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, ARRAY[0]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, ARRAY[1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::double precision, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
-- numeric
SELECT quantile(x::numeric, 0.5) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, 0.1) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, 0) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, 1) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, ARRAY[0.5]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, ARRAY[0.1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, ARRAY[0]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, ARRAY[1]) FROM generate_series(1,1000) s(x);
SELECT quantile(x::numeric, ARRAY[0, 0.1, 0.5, 0.75, 1]) FROM generate_series(1,1000) s(x);
ROLLBACK;

0 comments on commit 754d1cc

Please sign in to comment.