view src/testdir/test_random.vim @ 18713:baf890fa1621 v8.1.2348

patch 8.1.2348: :const cannot be followed by "| endif" Commit: https://github.com/vim/vim/commit/8f76e6b12b958f2779444a92234bbaf3f49eeb99 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Nov 26 16:50:30 2019 +0100 patch 8.1.2348: :const cannot be followed by "| endif" Problem: :const cannot be followed by "| endif". Solution: Check following command for :const. (closes https://github.com/vim/vim/issues/5269) Also fix completion after :const.
author Bram Moolenaar <Bram@vim.org>
date Tue, 26 Nov 2019 17:00:04 +0100
parents aef98a646d3e
children 2513e666aa82
line wrap: on
line source

" Tests for srand() and rand()

func Test_Rand()
  let r = srand(123456789)
  call assert_equal([123456789, 362436069, 521288629, 88675123], r)
  call assert_equal(3701687786, rand(r))
  call assert_equal(458299110, rand(r))
  call assert_equal(2500872618, rand(r))
  call assert_equal(3633119408, rand(r))
  call assert_equal(516391518, rand(r))

  call test_settime(12341234)
  let s = srand()
  if filereadable('/dev/urandom')
    " using /dev/urandom
    call assert_notequal(s, srand())
  else
    " using time()
    call assert_equal(s, srand())
    call test_settime(12341235)
    call assert_notequal(s, srand())
  endif

  call srand()
  let v = rand()
  call assert_notequal(v, rand())

  call assert_fails('echo srand([1])', 'E745:')
  call assert_fails('echo rand([1, 2, 3])', 'E475:')
  call assert_fails('echo rand([[1], 2, 3, 4])', 'E475:')
  call assert_fails('echo rand([1, [2], 3, 4])', 'E475:')
  call assert_fails('echo rand([1, 2, [3], 4])', 'E475:')
  call assert_fails('echo rand([1, 2, 3, [4]])', 'E475:')

  call test_settime(0)
endfunc