Permalink
Browse files

Added basic regression tests for PCSA estimator.

  • Loading branch information...
tvondra committed Apr 4, 2012
1 parent e38c749 commit 64cd9bc4a52fac1a5bbdb3d3e57d4a4143c7dfe5
Showing with 87 additions and 0 deletions.
  1. +4 −0 pcsa/Makefile
  2. +45 −0 pcsa/test/expected/base.out
  3. +38 −0 pcsa/test/sql/base.sql
View
@@ -5,6 +5,10 @@ EXTENSION = pcsa_counter
DATA = sql/pcsa_counter--1.0.sql
MODULES = pcsa_counter
+TESTS = $(wildcard test/sql/*.sql)
+REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
+REGRESS_OPTS = --inputdir=test --load-language=plpgsql
+
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
@@ -0,0 +1,45 @@
+BEGIN;
+CREATE EXTENSION pcsa_counter;
+SELECT pcsa_distinct(id, 32, 4) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+ val
+-----
+ t
+(1 row)
+
+SELECT pcsa_distinct(id::text, 32, 4) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+ val
+-----
+ t
+(1 row)
+
+DO LANGUAGE plpgsql $$
+DECLARE
+ v_counter pcsa_estimator := pcsa_init(32, 4);
+ v_counter2 pcsa_estimator := pcsa_init(32, 4);
+ v_estimate real;
+ v_tmp real;
+BEGIN
+
+ FOR i IN 1..10000 LOOP
+ PERFORM pcsa_add_item(v_counter, i);
+ PERFORM pcsa_add_item(v_counter2, i::text);
+ END LOOP;
+
+ SELECT pcsa_get_estimate(v_counter) INTO v_estimate;
+ IF (v_estimate BETWEEN 8000 AND 11000) THEN
+ RAISE NOTICE 'estimate OK';
+ ELSE
+ RAISE NOTICE 'estimate ERROR (%)',v_estimate;
+ END IF;
+
+ SELECT pcsa_get_estimate(v_counter2) INTO v_estimate;
+ IF (v_estimate BETWEEN 8000 AND 11000) THEN
+ RAISE NOTICE 'estimate OK';
+ ELSE
+ RAISE NOTICE 'estimate ERROR (%)',v_estimate;
+ END IF;
+
+END$$;
+NOTICE: estimate OK
+NOTICE: estimate OK
+ROLLBACK;
View
@@ -0,0 +1,38 @@
+BEGIN;
+
+CREATE EXTENSION pcsa_counter;
+
+SELECT pcsa_distinct(id, 32, 4) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+
+SELECT pcsa_distinct(id::text, 32, 4) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+
+DO LANGUAGE plpgsql $$
+DECLARE
+ v_counter pcsa_estimator := pcsa_init(32, 4);
+ v_counter2 pcsa_estimator := pcsa_init(32, 4);
+ v_estimate real;
+ v_tmp real;
+BEGIN
+
+ FOR i IN 1..10000 LOOP
+ PERFORM pcsa_add_item(v_counter, i);
+ PERFORM pcsa_add_item(v_counter2, i::text);
+ END LOOP;
+
+ SELECT pcsa_get_estimate(v_counter) INTO v_estimate;
+ IF (v_estimate BETWEEN 8000 AND 11000) THEN
+ RAISE NOTICE 'estimate OK';
+ ELSE
+ RAISE NOTICE 'estimate ERROR (%)',v_estimate;
+ END IF;
+
+ SELECT pcsa_get_estimate(v_counter2) INTO v_estimate;
+ IF (v_estimate BETWEEN 8000 AND 11000) THEN
+ RAISE NOTICE 'estimate OK';
+ ELSE
+ RAISE NOTICE 'estimate ERROR (%)',v_estimate;
+ END IF;
+
+END$$;
+
+ROLLBACK;

0 comments on commit 64cd9bc

Please sign in to comment.