Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update python test template to avoid name clashes #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/main/resources/templates/filetest/py.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TEST CODE FOR PYTHON {{{
import sys, time, math
import sys as _sys
import time as _time
import math as _math

def tc_equal(expected, received):
try:
Expand All @@ -11,7 +13,7 @@ def tc_equal(expected, received):
elif _t == float:
eps = 1e-9
d = abs(received - expected)
return not math.isnan(received) and not math.isnan(expected) and d <= eps * max(1.0, abs(expected))
return not _math.isnan(received) and not _math.isnan(expected) and d <= eps * max(1.0, abs(expected))
else:
return expected == received
except:
Expand All @@ -26,36 +28,36 @@ def pretty_str(x):
return str(x)

def do_test(${Method.Params}, __expected):
startTime = time.time()
startTime = _time.time()
instance = ${ClassName}()
exception = None
try:
__result = instance.${Method.Name}(${foreach Method.Params par , }${par.Name}${end});
except:
import traceback
exception = traceback.format_exc()
elapsed = time.time() - startTime # in sec
elapsed = _time.time() - startTime # in sec

if exception is not None:
sys.stdout.write("RUNTIME ERROR: \\n")
sys.stdout.write(exception + "\\n")
_sys.stdout.write("RUNTIME ERROR: \\n")
_sys.stdout.write(exception + "\\n")
return 0

if tc_equal(__expected, __result):
sys.stdout.write("PASSED! " + ("(%.3f seconds)" % elapsed) + "\\n")
_sys.stdout.write("PASSED! " + ("(%.3f seconds)" % elapsed) + "\\n")
return 1
else:
sys.stdout.write("FAILED! " + ("(%.3f seconds)" % elapsed) + "\\n")
sys.stdout.write(" Expected: " + pretty_str(__expected) + "\\n")
sys.stdout.write(" Received: " + pretty_str(__result) + "\\n")
_sys.stdout.write("FAILED! " + ("(%.3f seconds)" % elapsed) + "\\n")
_sys.stdout.write(" Expected: " + pretty_str(__expected) + "\\n")
_sys.stdout.write(" Received: " + pretty_str(__result) + "\\n")
return 0

def run_tests():
sys.stdout.write("${Problem.Name} (${Problem.Score} Points)\\n\\n")
_sys.stdout.write("${Problem.Name} (${Problem.Score} Points)\\n\\n")

passed = cases = 0
case_set = set()
for arg in sys.argv[1:]:
for arg in _sys.argv[1:]:
case_set.add(int(arg))

with open("${Dependencies.testcase.GeneratedFileName}", "r") as f:
Expand Down Expand Up @@ -85,16 +87,16 @@ ${<end}

cases += 1
if len(case_set) > 0 and (cases - 1) in case_set: continue
sys.stdout.write(" Testcase #%d ... " % (cases - 1))
_sys.stdout.write(" Testcase #%d ... " % (cases - 1))
passed += do_test(${foreach Method.Params param , }${param.Name}${end}, __answer)

sys.stdout.write("\\nPassed : %d / %d cases\\n" % (passed, cases))
_sys.stdout.write("\\nPassed : %d / %d cases\\n" % (passed, cases))

T = time.time() - ${CreateTime}
T = _time.time() - ${CreateTime}
PT, TT = (T / 60.0, 75.0)
points = ${Problem.Score} * (0.3 + (0.7 * TT * TT) / (10.0 * PT * PT + TT * TT))
sys.stdout.write("Time : %d minutes %d secs\\n" % (int(T/60), T%60))
sys.stdout.write("Score : %.2f points\\n" % points)
_sys.stdout.write("Time : %d minutes %d secs\\n" % (int(T/60), T%60))
_sys.stdout.write("Score : %.2f points\\n" % points)

if __name__ == '__main__':
run_tests()
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/greed/template/TestModelFixtures.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static Map<String, Object> buildStubbingModel() {
new ParamValue(param3, valueList1)
}, new ParamValue(new Param("return", retType, 0), valueList2));

Problem problem = new Problem("Test", 250, "TestClass", 2000, 256, method, new Testcase[]{case0}, null);
Problem problem = new Problem("Test", 250, "TestClass", 2000, 256, false, method, new Testcase[]{case0}, null);

Map<String, Object> model = new HashMap<String, Object>();
model.put("Problem", problem);
Expand Down