-- verifies an evaulator of expressions in PN (polish/prefix notation)
-- expects evaluator as function "solution"
-- returns true upon correct verification
-- assert some stuff for better error messages
assert(log, "log")
function check(output, input)
local s = tostring(solution(input))
assert(log, "log")("check "..s)
if s == output then
log("OK: "..input.." => "..output)
else
log("Oops: "..input.." => "..s.." (expected: "..output..")")
error("verification failed")
end
end
check("3", "+ 1 2")
check("6", "* 2 3")
return truetest run test run with input pitch download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
2 comment(s) hidden. show
| Recognizer | Recognition Result | Visualize | Recalc |
|---|---|---|---|
| #308 | 577 | [visualize] |
| Snippet ID: | #38 |
| Snippet name: | Test case for PN calculator |
| Eternal ID of this version: | #38/1 |
| Text MD5: | 8d0daf047ece273b96b822b594644fc6 |
| Author: | stefan |
| Category: | |
| Type: | Lua code - Test case |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2013-12-21 07:14:22 |
| Source code size: | 577 bytes / 22 lines |
| Pitched / IR pitched: | Yes / Yes |
| Views / Downloads: | 2588 / 691 |
| Referenced in: | [show references] |