robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

dundargoctest: move oldtests to test directory (#22536)af23d17388

master
1.6 KiB59 linesraw
1" Tests for srand() and rand()
2
3source check.vim
4source shared.vim
5
6func Test_Rand()
7  let r = srand(123456789)
8  call assert_equal([1573771921, 319883699, 2742014374, 1324369493], r)
9  call assert_equal(4284103975, rand(r))
10  call assert_equal(1001954530, rand(r))
11  call assert_equal(2701803082, rand(r))
12  call assert_equal(2658065534, rand(r))
13  call assert_equal(3104308804, rand(r))
14
15  let s = srand()
16  " using /dev/urandom or used time, result is different each time
17  call assert_notequal(s, srand())
18
19  " Nvim does not support test_srand_seed
20  " call test_srand_seed(123456789)
21  " call assert_equal(4284103975, rand())
22  " call assert_equal(1001954530, rand())
23  " call test_srand_seed()
24
25  if has('float')
26    call assert_fails('echo srand(1.2)', 'E805:')
27  endif
28  call assert_fails('echo srand([1])', 'E745:')
29  call assert_fails('echo rand("burp")', 'E475:')
30  call assert_fails('echo rand([1, 2, 3])', 'E730:')
31  call assert_fails('echo rand([[1], 2, 3, 4])', 'E730:')
32  call assert_fails('echo rand([1, [2], 3, 4])', 'E730:')
33  call assert_fails('echo rand([1, 2, [3], 4])', 'E730:')
34  call assert_fails('echo rand([1, 2, 3, [4]])', 'E730:')
35endfunc
36
37func Test_issue_5587()
38  call rand()
39  call garbagecollect()
40  call rand()
41endfunc
42
43func Test_srand()
44  CheckNotGui
45
46  let cmd = GetVimCommand() .. ' -V -es -c "echo rand()" -c qa!'
47  let bad = 0
48  for _ in range(10)
49    echo cmd
50    let result1 = system(cmd)
51    let result2 = system(cmd)
52    if result1 ==# result2
53      let bad += 1
54    endif
55  endfor
56  call assert_inrange(0, 4, bad)
57endfunc
58
59" vim: shiftwidth=2 sts=2 expandtab