annotate src/testdir/test_random.vim @ 32357:5e2f81645b10 v9.0.1510

patch 9.0.1510: misleading variable name for error message Commit: https://github.com/vim/vim/commit/70e8028a4d63c83f67bc3314d064613e2041e462 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 5 22:58:34 2023 +0100 patch 9.0.1510: misleading variable name for error message Problem: Misleading variable name for error message. Solution: Change "name" to "number". (closes https://github.com/vim/vim/issues/12345)
author Bram Moolenaar <Bram@vim.org>
date Sat, 06 May 2023 00:00:03 +0200
parents a267e07ded3b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
31363
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
3 source check.vim
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
4 source shared.vim
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
5
18701
128662297ddf patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 func Test_Rand()
128662297ddf patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 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
8 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
9 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
10 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
11 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
12 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
13 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
14
128662297ddf patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 let s = srand()
31367
a267e07ded3b patch 9.0.1017: test for srand() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 31363
diff changeset
16 " using /dev/urandom or used time, result is different each time
a267e07ded3b patch 9.0.1017: test for srand() fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 31363
diff changeset
17 call assert_notequal(s, srand())
18701
128662297ddf patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
19350
76cb39bf1871 patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents: 18734
diff changeset
19 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
20 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
21 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
22 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
23
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
24 call assert_fails('echo srand(1.2)', 'E805:')
18701
128662297ddf patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 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
26 call assert_fails('echo rand("burp")', 'E475:')
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 19350
diff changeset
27 call assert_fails('echo rand([1, 2, 3])', 'E730:')
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 19350
diff changeset
28 call assert_fails('echo rand([[1], 2, 3, 4])', 'E730:')
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 19350
diff changeset
29 call assert_fails('echo rand([1, [2], 3, 4])', 'E730:')
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 19350
diff changeset
30 call assert_fails('echo rand([1, 2, [3], 4])', 'E730:')
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 19350
diff changeset
31 call assert_fails('echo rand([1, 2, 3, [4]])', 'E730:')
18701
128662297ddf patch 8.1.2342: random number generator in Vim script is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 endfunc
19350
76cb39bf1871 patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents: 18734
diff changeset
33
76cb39bf1871 patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents: 18734
diff changeset
34 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
35 call rand()
76cb39bf1871 patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents: 18734
diff changeset
36 call garbagecollect()
76cb39bf1871 patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents: 18734
diff changeset
37 call rand()
76cb39bf1871 patch 8.2.0233: crash when using garbagecollect() in between rand()
Bram Moolenaar <Bram@vim.org>
parents: 18734
diff changeset
38 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
39
31363
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
40 func Test_srand()
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
41 CheckNotGui
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
42
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
43 let cmd = GetVimCommand() .. ' -V -es -c "echo rand()" -c qa!'
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
44 let bad = 0
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
45 for _ in range(10)
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
46 echo cmd
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
47 let result1 = system(cmd)
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
48 let result2 = system(cmd)
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
49 if result1 ==# result2
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
50 let bad += 1
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
51 endif
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
52 endfor
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
53 call assert_inrange(0, 4, bad)
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
54 endfunc
0608de106485 patch 9.0.1015: without /dev/urandom srand() seed is too predictable
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
55
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
56 " vim: shiftwidth=2 sts=2 expandtab