Skip to content
Browse files

Basic regression test suite for probabilistic estimator.

  • Loading branch information...
1 parent 4c12d83 commit 154b046d158b9a4968a9cb19d31d06d5885da150 @tvondra committed
Showing with 87 additions and 0 deletions.
  1. +4 −0 probabilistic/Makefile
  2. +45 −0 probabilistic/test/expected/base.out
  3. +38 −0 probabilistic/test/sql/base.sql
View
4 probabilistic/Makefile
@@ -5,6 +5,10 @@ EXTENSION = probabilistic_counter
DATA = sql/probabilistic_counter--1.0.sql
MODULES = probabilistic_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)
View
45 probabilistic/test/expected/base.out
@@ -0,0 +1,45 @@
+BEGIN;
+CREATE EXTENSION probabilistic_counter;
+SELECT probabilistic_distinct(id, 4, 32) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+ val
+-----
+ t
+(1 row)
+
+SELECT probabilistic_distinct(id::text, 4, 32) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+ val
+-----
+ t
+(1 row)
+
+DO LANGUAGE plpgsql $$
+DECLARE
+ v_counter probabilistic_estimator := probabilistic_init(4, 32);
+ v_counter2 probabilistic_estimator := probabilistic_init(4, 32);
+ v_estimate real;
+ v_tmp real;
+BEGIN
+
+ FOR i IN 1..10000 LOOP
+ PERFORM probabilistic_add_item(v_counter, i);
+ PERFORM probabilistic_add_item(v_counter2, i::text);
+ END LOOP;
+
+ SELECT probabilistic_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 probabilistic_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
38 probabilistic/test/sql/base.sql
@@ -0,0 +1,38 @@
+BEGIN;
+
+CREATE EXTENSION probabilistic_counter;
+
+SELECT probabilistic_distinct(id, 4, 32) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+
+SELECT probabilistic_distinct(id::text, 4, 32) BETWEEN 90000 AND 110000 val FROM generate_series(1,100000) s(id);
+
+DO LANGUAGE plpgsql $$
+DECLARE
+ v_counter probabilistic_estimator := probabilistic_init(4, 32);
+ v_counter2 probabilistic_estimator := probabilistic_init(4, 32);
+ v_estimate real;
+ v_tmp real;
+BEGIN
+
+ FOR i IN 1..10000 LOOP
+ PERFORM probabilistic_add_item(v_counter, i);
+ PERFORM probabilistic_add_item(v_counter2, i::text);
+ END LOOP;
+
+ SELECT probabilistic_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 probabilistic_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 154b046

Please sign in to comment.
Something went wrong with that request. Please try again.