-- 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
| ID | Author/Program | Comment | Date | |
|---|---|---|---|---|
| 407 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { -- 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 true }} | 2015-08-18 13:28:19 | delete |
| 405 | #1000604 (pitcher) | 2015-08-20 15:28:24 |
| 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: | 2595 / 691 |
| Referenced in: | [show references] |