File: cl_random_seed.lua

package info (click to toggle)
lua-busted 2.0~rc12-1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 656 kB
  • ctags: 310
  • sloc: sh: 191; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- supporting testfile; belongs to 'cl_spec.lua'
-- executed with --seed=12345
local order = {}

describe('Randomizing test order with pre-defined seed', function()
  randomize()

  for i = 1, 10 do
    it('does 10 its', function()
      table.insert(order, i)
    end)
  end
end)

describe('Order of tests ran', function()
  randomize()

  it('randomized with known random seed', function()
    math.randomseed(12345)
    local t = {}
    for i = 1, 10 do
      table.insert(t, i)
    end
    local n = #t
    while n >= 1 do
      local k = math.random(n)
      t[n], t[k] = t[k], t[n]
      n = n - 1
    end
    local expected = t
    assert.are.same(expected, order)
  end)
end)