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