Skip to content

Commit

Permalink
molly: update an RW register generator
Browse files Browse the repository at this point in the history
Elle's checker requires that operations on RW register
must not write same numbers. The patch changes an RW-register
operations generator in that way, every number emit only once.
Also, a max number can be specified in `rw_register_gen()`,
default value is equal to 1000.
  • Loading branch information
ligurio committed Nov 7, 2024
1 parent 26258a1 commit fcb07ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow chaining `luafun` iterators with iterators defined in Molly and vice versa.
- Using of SQL prepared statements in test examples.
- Generated operation can be any callable Lua object.
- RW-register generator emits every number only once.

### Removed

Expand Down
25 changes: 19 additions & 6 deletions molly/tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ local gen_lib = require('molly.gen')
local json = require('molly.json')

-- Function that describes a 'read' operation.
local function op_r()
local function rw_register_op_r()
return setmetatable({
f = 'txn',
value = {{
Expand All @@ -126,13 +126,13 @@ local function op_r()
end

-- Function that describes a 'write' operation.
local function op_w()
local function rw_register_op_w(n)
return setmetatable({
f = 'txn',
value = {{
'w',
'x',
math.random(1, 100),
n,
}}
}, {
__type = '<operation>',
Expand All @@ -142,8 +142,12 @@ local function op_w()
})
end

--- Write/Read operations generator.
--- An RW-register operations generator.
--
-- A generator for operations where values are transactions made
-- up of reads and appends to various integer keys.
-- @table[opt] opts A table with options.
-- @number[opt] opts.max_n A maximum number. Default is 1000.
-- @usage
--
-- > log = require('log')
Expand All @@ -165,8 +169,17 @@ end
-- @return an iterator
--
-- @function rw_register_gen
local function rw_register_gen()
return gen_lib.cycle(gen_lib.iter({ op_r, op_w }))
local function rw_register_gen(opts)
dev_checks('?table')

opts = opts or {}
local param = {}
param.max_n = opts.max_n or 1000

assert(type(param.max_n) == 'number', 'max_n must be a number')

return gen_lib.mix(gen_lib.range(param.max_n):map(rw_register_op_w),
gen_lib.iter({rw_register_op_r}):cycle())
end

-- Function that describes a 'read' operation.
Expand Down

0 comments on commit fcb07ac

Please sign in to comment.