diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-02-13 15:07:37 +0100 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-02-13 15:07:37 +0100 |
| commit | a5ffa54ee71c9819fc413fdf118774b1db21a1df (patch) | |
| tree | 4072ed7df7c89395386074acfd45f8e47e59c8a6 /spec/02-random_spec.lua | |
| parent | f6f0c77995fcd62863a7f24cbb407a68d2277759 (diff) | |
| download | luasystem-a5ffa54ee71c9819fc413fdf118774b1db21a1df.tar.gz luasystem-a5ffa54ee71c9819fc413fdf118774b1db21a1df.tar.bz2 luasystem-a5ffa54ee71c9819fc413fdf118774b1db21a1df.zip | |
align error handling
Diffstat (limited to 'spec/02-random_spec.lua')
| -rw-r--r-- | spec/02-random_spec.lua | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/spec/02-random_spec.lua b/spec/02-random_spec.lua index db5d5ce..7b2eea6 100644 --- a/spec/02-random_spec.lua +++ b/spec/02-random_spec.lua | |||
| @@ -155,24 +155,27 @@ describe("Random:", function() | |||
| 155 | end) | 155 | end) |
| 156 | 156 | ||
| 157 | 157 | ||
| 158 | it("returns nil and error for empty interval (m > n)", function() | 158 | it("throws for empty interval (m > n), like math.random", function() |
| 159 | local v, err = system.rnd(10, 5) | 159 | local ok_math, _ = pcall(math.random, 10, 5) |
| 160 | assert.is_falsy(v) | 160 | assert.is_falsy(ok_math, "math.random(10, 5) should error") |
| 161 | assert.are.equal("interval is empty", err) | 161 | local ok_rnd, _ = pcall(system.rnd, 10, 5) |
| 162 | assert.is_falsy(ok_rnd, "rnd(10, 5) should throw like math.random") | ||
| 162 | end) | 163 | end) |
| 163 | 164 | ||
| 164 | 165 | ||
| 165 | it("returns nil and error for invalid one-arg (m < 1, m ~= 0)", function() | 166 | it("throws for invalid one-arg (m < 1, m ~= 0), like math.random", function() |
| 166 | local v, err = system.rnd(-1) | 167 | local ok_math, _ = pcall(math.random, -1) |
| 167 | assert.is_falsy(v) | 168 | assert.is_falsy(ok_math, "math.random(-1) should error") |
| 168 | assert.are.equal("interval is empty", err) | 169 | local ok_rnd, _ = pcall(system.rnd, -1) |
| 170 | assert.is_falsy(ok_rnd, "rnd(-1) should throw like math.random") | ||
| 169 | end) | 171 | end) |
| 170 | 172 | ||
| 171 | 173 | ||
| 172 | it("returns nil and error for wrong number of arguments", function() | 174 | it("throws for wrong number of arguments, like math.random", function() |
| 173 | local v, err = system.rnd(1, 2, 3) | 175 | local ok_math, _ = pcall(math.random, 1, 2, 3) |
| 174 | assert.is_falsy(v) | 176 | assert.is_falsy(ok_math, "math.random(1, 2, 3) should error") |
| 175 | assert.are.equal("wrong number of arguments", err) | 177 | local ok_rnd, _ = pcall(system.rnd, 1, 2, 3) |
| 178 | assert.is_falsy(ok_rnd, "rnd(1, 2, 3) should throw like math.random") | ||
| 176 | end) | 179 | end) |
| 177 | 180 | ||
| 178 | end) | 181 | end) |
