Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #38 // Test case for PN calculator

Lua code - Test case

1  
-- verifies an evaulator of expressions in PN (polish/prefix notation)
2  
-- expects evaluator as function "solution"
3  
-- returns true upon correct verification
4  
5  
-- assert some stuff for better error messages
6  
assert(log, "log")
7  
8  
function check(output, input)
9  
  local s = tostring(solution(input))
10  
  assert(log, "log")("check "..s)
11  
  if s == output then
12  
    log("OK: "..input.." => "..output)
13  
  else
14  
    log("Oops: "..input.." => "..s.." (expected: "..output..")")
15  
    error("verification failed")
16  
  end
17  
end
18  
19  
check("3", "+ 1 2")
20  
check("6", "* 2 3")
21  
22  
return true

test run  test run with input  pitch  download  show line numbers   

Relations

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

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

add comment

Image recognition results

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: 1660 / 539
Referenced in: [show references]