interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / stmtrand.test

48 lines · 1742 bytes Raw Blame History
1# 2024-05-24
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# Verify that the stmtrand() extension function works.
13#
14# Stmtrand() is a pseudo-random number generator designed for testing.
15# it has the property that it returns the same sequence of pseudo-random
16# numbers for each SQL statement invocation. This makes it suitable for
17# testing because the results are reproducible.
18#
19# The optional argument is the seed for the PRNG. The seed is only used
20# on the first invocation. If the argument is omitted, a seed of 0 is
21# used.
22#
23
24set testdir [file dirname $argv0]
25source $testdir/tester.tcl
26set testprefix stmtrand
27
28load_static_extension db stmtrand
29
30do_execsql_test 1.1 {
31 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<30)
32 SELECT stmtrand()%10 FROM c
33} {4 1 8 3 6 1 4 9 2 1 2 1 0 1 8 1 4 7 6 1 8 7 0 3 0 9 4 5 9 9}
34do_execsql_test 1.2 {
35 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<30)
36 SELECT stmtrand(0)%10 FROM c
37} {4 1 8 3 6 1 4 9 2 1 2 1 0 1 8 1 4 7 6 1 8 7 0 3 0 9 4 5 9 9}
38do_execsql_test 1.3 {
39 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<30)
40 SELECT stmtrand(1)%10 FROM c
41} {3 8 9 4 7 2 3 8 5 2 7 0 3 0 7 2 5 6 1 8 5 6 7 8 7 2 9 6 8 0}
42do_execsql_test 1.4 {
43 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<30)
44 SELECT stmtrand(x)%10 FROM c
45} {3 8 9 4 7 2 3 8 5 2 7 0 3 0 7 2 5 6 1 8 5 6 7 8 7 2 9 6 8 0}
46
47
48finish_test