Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6812e95

Browse files
committed
Improve random regression tests to fail less frequently.
1 parent98bb1d2 commit6812e95

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-
WHERErandom NOT BETWEEN 80 AND 120;
32-
random
33-
--------
47+
SELECTAVG(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
SELECTcount(*)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 unique1AS random
11+
FROM onekORDER BY random()LIMIT1)
12+
INTERSECT
13+
(SELECT unique1AS random
14+
FROM onekORDER BY random()LIMIT1)
15+
INTERSECT
16+
(SELECT unique1AS random
17+
FROM onekORDER BY random()LIMIT1);
18+
19+
-- count roughly 1/10 of the tuples
1420
SELECTcount(*)AS random INTO RANDOM_TBL
1521
FROM onekWHERE random()<1.0/10;
1622

@@ -19,10 +25,20 @@ INSERT INTO RANDOM_TBL (random)
1925
SELECTcount(*)
2026
FROM onekWHERE 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+
SELECTcount(*)
31+
FROM onekWHERE random()<1.0/10;
32+
33+
-- select again, the count should be different
34+
INSERT INTO RANDOM_TBL (random)
35+
SELECTcount(*)
36+
FROM onekWHERE random()<1.0/10;
37+
38+
-- now test that they are different counts
2339
SELECT random,count(random)FROM RANDOM_TBL
24-
GROUP BY randomHAVINGcount(random)>1;
40+
GROUP BY randomHAVINGcount(random)>3;
2541

26-
SELECT randomFROM RANDOM_TBL
27-
WHERErandom NOT BETWEEN80AND120;
42+
SELECTAVG(random)FROM RANDOM_TBL
43+
HAVINGAVG(random) NOT BETWEEN80AND120;
2844

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp