Skip to content

Commit

Permalink
program.lwaftr.tests.propbased.genyang: adapt to new range format
Browse files Browse the repository at this point in the history
When hacking the range validator I had misunderstood the format used
to express YANG range restrictions (I thought it didn’t feature
multiple intervals), and changed it along the way. I think the new
format is a bit simpler though (more regular) and requires less special
cases, so I decided to keep it.
  • Loading branch information
eugeneia committed Jan 12, 2018
1 parent d1a7409 commit e577721
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/program/lwaftr/tests/propbased/genyang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,8 @@ local function choose_range(rng, lo, hi)

if #rng == 0 or (generate_invalid and r < 0.1) then
return choose_bounded(lo, hi)
elseif rng[1] == "or" then
local intervals = {}
local num_intervals = (#rng - 1) / 2

for i=1, num_intervals do
intervals[i] = { rng[2*i], rng[2*i+1] }
end

return choose_range(choose(intervals), lo, hi)
else
local lo_rng, hi_rng = rng[1], rng[2]
local lo_rng, hi_rng = unpack(choose(rng))

if lo_rng == "min" then
lo_rng = lo
Expand Down Expand Up @@ -526,11 +517,11 @@ function selftest()
-- check some int types with range statements
for i=1, 100 do
local val1 = value_from_type({ primitive_type="uint8",
range={ value = {1, 16} } })
range={ value = {{1, 16}} } })
local val2 = value_from_type({ primitive_type="uint8",
range={ value = {"or", 1, 16, 18, 32} } })
range={ value = {{1, 16}, {18, 32}} } })
local val3 = value_from_type({ primitive_type="uint8",
range={ value = {"or", "min", 10, 250, "max"} } })
range={ value = {{'min', 10}, {250, 'max'}} } })
assert(val1 >= 1 and val1 <= 16, string.format("test value: %d", val1))
assert(val2 >= 1 and val2 <= 32 and val2 ~= 17,
string.format("test value: %d", val2))
Expand Down

0 comments on commit e577721

Please sign in to comment.