Skip to content

Commit 6812e95

Browse files
committed
Improve random regression tests to fail less frequently.
1 parent 98bb1d2 commit 6812e95

File tree

2 files changed

+55
-22
lines changed

2 files changed

+55
-22
lines changed

src/test/regress/expected/random.out

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,51 @@
22
-- RANDOM
33
-- Test the random function
44
--
5-
-- count the number of tuples originally
5+
-- count the number of tuples originally, should be 1000
66
SELECT count(*) FROM onek;
77
count
88
-------
99
1000
1010
(1 row)
1111

12-
-- select roughly 1/10 of the tuples
13-
-- Assume that the "onek" table has 1000 tuples
14-
-- and try to bracket the correct number so we
15-
-- have a regression test which can pass/fail
16-
-- - thomas 1998-08-17
12+
-- pick three random rows, they shouldn't match
13+
(SELECT unique1 AS random
14+
FROM onek ORDER BY random() LIMIT 1)
15+
INTERSECT
16+
(SELECT unique1 AS random
17+
FROM onek ORDER BY random() LIMIT 1)
18+
INTERSECT
19+
(SELECT unique1 AS random
20+
FROM onek ORDER BY random() LIMIT 1);
21+
random
22+
--------
23+
(0 rows)
24+
25+
-- count roughly 1/10 of the tuples
1726
SELECT count(*) AS random INTO RANDOM_TBL
1827
FROM onek WHERE random() < 1.0/10;
1928
-- select again, the count should be different
2029
INSERT INTO RANDOM_TBL (random)
2130
SELECT count(*)
2231
FROM onek WHERE random() < 1.0/10;
23-
-- now test the results for randomness in the correct range
32+
-- select again, the count should be different
33+
INSERT INTO RANDOM_TBL (random)
34+
SELECT count(*)
35+
FROM onek WHERE random() < 1.0/10;
36+
-- select again, the count should be different
37+
INSERT INTO RANDOM_TBL (random)
38+
SELECT count(*)
39+
FROM onek WHERE random() < 1.0/10;
40+
-- now test that they are different counts
2441
SELECT random, count(random) FROM RANDOM_TBL
25-
GROUP BY random HAVING count(random) > 1;
42+
GROUP BY random HAVING count(random) > 3;
2643
random | count
2744
--------+-------
2845
(0 rows)
2946

30-
SELECT random FROM RANDOM_TBL
31-
WHERE random NOT BETWEEN 80 AND 120;
32-
random
33-
--------
47+
SELECT AVG(random) FROM RANDOM_TBL
48+
HAVING AVG(random) NOT BETWEEN 80 AND 120;
49+
avg
50+
-----
3451
(0 rows)
3552

src/test/regress/sql/random.sql

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
-- Test the random function
44
--
55

6-
-- count the number of tuples originally
6+
-- count the number of tuples originally, should be 1000
77
SELECT count(*) FROM onek;
88

9-
-- select roughly 1/10 of the tuples
10-
-- Assume that the "onek" table has 1000 tuples
11-
-- and try to bracket the correct number so we
12-
-- have a regression test which can pass/fail
13-
-- - thomas 1998-08-17
9+
-- pick three random rows, they shouldn't match
10+
(SELECT unique1 AS random
11+
FROM onek ORDER BY random() LIMIT 1)
12+
INTERSECT
13+
(SELECT unique1 AS random
14+
FROM onek ORDER BY random() LIMIT 1)
15+
INTERSECT
16+
(SELECT unique1 AS random
17+
FROM onek ORDER BY random() LIMIT 1);
18+
19+
-- count roughly 1/10 of the tuples
1420
SELECT count(*) AS random INTO RANDOM_TBL
1521
FROM onek WHERE random() < 1.0/10;
1622

@@ -19,10 +25,20 @@ INSERT INTO RANDOM_TBL (random)
1925
SELECT count(*)
2026
FROM onek WHERE random() < 1.0/10;
2127

22-
-- now test the results for randomness in the correct range
28+
-- select again, the count should be different
29+
INSERT INTO RANDOM_TBL (random)
30+
SELECT count(*)
31+
FROM onek WHERE random() < 1.0/10;
32+
33+
-- select again, the count should be different
34+
INSERT INTO RANDOM_TBL (random)
35+
SELECT count(*)
36+
FROM onek WHERE random() < 1.0/10;
37+
38+
-- now test that they are different counts
2339
SELECT random, count(random) FROM RANDOM_TBL
24-
GROUP BY random HAVING count(random) > 1;
40+
GROUP BY random HAVING count(random) > 3;
2541

26-
SELECT random FROM RANDOM_TBL
27-
WHERE random NOT BETWEEN 80 AND 120;
42+
SELECT AVG(random) FROM RANDOM_TBL
43+
HAVING AVG(random) NOT BETWEEN 80 AND 120;
2844

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy