Mercurial > vim
annotate src/testdir/test_random.vim @ 20888:3c8982150ffe
Added tag v8.2.0995 for changeset 5dd8e741060bad01be8f394c526ab0315ecc7586
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 17 Jun 2020 20:45:04 +0200 |
parents | 76cb39bf1871 |
children | 6a4806e326dd |
rev | line source |
---|---|
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Tests for srand() and rand() |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func Test_Rand() |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 let r = srand(123456789) |
18732
2513e666aa82
patch 8.1.2356: rand() does not use the best algorithm
Bram Moolenaar <Bram@vim.org>
parents:
18703
diff
changeset
|
5 call assert_equal([1573771921, 319883699, 2742014374, 1324369493], r) |
2513e666aa82
patch 8.1.2356: rand() does not use the best algorithm
Bram Moolenaar <Bram@vim.org>
parents:
18703
diff
changeset
|
6 call assert_equal(4284103975, rand(r)) |
2513e666aa82
patch 8.1.2356: rand() does not use the best algorithm
Bram Moolenaar <Bram@vim.org>
parents:
18703
diff
changeset
|
7 call assert_equal(1001954530, rand(r)) |
2513e666aa82
patch 8.1.2356: rand() does not use the best algorithm
Bram Moolenaar <Bram@vim.org>
parents:
18703
diff
changeset
|
8 call assert_equal(2701803082, rand(r)) |
2513e666aa82
patch 8.1.2356: rand() does not use the best algorithm
Bram Moolenaar <Bram@vim.org>
parents:
18703
diff
changeset
|
9 call assert_equal(2658065534, rand(r)) |
2513e666aa82
patch 8.1.2356: rand() does not use the best algorithm
Bram Moolenaar <Bram@vim.org>
parents:
18703
diff
changeset
|
10 call assert_equal(3104308804, rand(r)) |
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 call test_settime(12341234) |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 let s = srand() |
19350
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
14 if !has('win32') && filereadable('/dev/urandom') |
18703
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
15 " using /dev/urandom |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
16 call assert_notequal(s, srand()) |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
17 else |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
18 " using time() |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
19 call assert_equal(s, srand()) |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
20 call test_settime(12341235) |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
21 call assert_notequal(s, srand()) |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
22 endif |
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
19350
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
24 call test_srand_seed(123456789) |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
25 call assert_equal(4284103975, rand()) |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
26 call assert_equal(1001954530, rand()) |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
27 call test_srand_seed() |
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 |
18734
c477006e8857
patch 8.1.2357: no test with wrong argument for rand()
Bram Moolenaar <Bram@vim.org>
parents:
18732
diff
changeset
|
29 if has('float') |
c477006e8857
patch 8.1.2357: no test with wrong argument for rand()
Bram Moolenaar <Bram@vim.org>
parents:
18732
diff
changeset
|
30 call assert_fails('echo srand(1.2)', 'E805:') |
c477006e8857
patch 8.1.2357: no test with wrong argument for rand()
Bram Moolenaar <Bram@vim.org>
parents:
18732
diff
changeset
|
31 endif |
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 call assert_fails('echo srand([1])', 'E745:') |
18734
c477006e8857
patch 8.1.2357: no test with wrong argument for rand()
Bram Moolenaar <Bram@vim.org>
parents:
18732
diff
changeset
|
33 call assert_fails('echo rand("burp")', 'E475:') |
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 call assert_fails('echo rand([1, 2, 3])', 'E475:') |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 call assert_fails('echo rand([[1], 2, 3, 4])', 'E475:') |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 call assert_fails('echo rand([1, [2], 3, 4])', 'E475:') |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 call assert_fails('echo rand([1, 2, [3], 4])', 'E475:') |
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 call assert_fails('echo rand([1, 2, 3, [4]])', 'E475:') |
18703
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
39 |
aef98a646d3e
patch 8.1.2343: using time() for srand() is not very random
Bram Moolenaar <Bram@vim.org>
parents:
18701
diff
changeset
|
40 call test_settime(0) |
18701
128662297ddf
patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 endfunc |
19350
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
42 |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
43 func Test_issue_5587() |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
44 call rand() |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
45 call garbagecollect() |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
46 call rand() |
76cb39bf1871
patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents:
18734
diff
changeset
|
47 endfunc |