From a7d14ee0dccacb71a9b9409831ef0813292dce77 Mon Sep 17 00:00:00 2001 From: MartinXPN Date: Thu, 15 Jul 2021 05:47:33 +0400 Subject: [PATCH] added float output comparison (3 decimal digits) --- hello_world/app.py | 14 +++++++++++++- template.yaml | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hello_world/app.py b/hello_world/app.py index 025c460..6efb2af 100644 --- a/hello_world/app.py +++ b/hello_world/app.py @@ -1,7 +1,7 @@ import glob +import json import subprocess import zipfile -import json from pathlib import Path from threading import Timer @@ -23,6 +23,8 @@ def run_shell(command: str, timeout: float, memory_limit_mb: int = 512): outs, errs = proc.communicate(timeout=timeout) if outs: outs = outs.decode('utf-8') if errs: errs = errs.decode('utf-8') + if proc.returncode != 0: + errs = 'Runtime error - did not exit with exit code 0' except subprocess.TimeoutExpired: outs, errs = None, 'Time limit exceeded' except MemoryError: @@ -35,6 +37,14 @@ def run_shell(command: str, timeout: float, memory_limit_mb: int = 512): return outs, errs +def is_float(value: str): + try: + float(value) + return True + except ValueError: + return False + + def lambda_handler(event, context): print('Event:', event) print('Context:', context) @@ -107,6 +117,8 @@ def lambda_handler(event, context): with open(output_file, 'r') as f: target = f.read().strip() + if is_float(target) and is_float(output): + target, output = f'{float(target):.3f}', f'{float(output):.3f}' if target != output: print('Wrong answer!') print('Output:', output) diff --git a/template.yaml b/template.yaml index b0d9428..3f5a921 100644 --- a/template.yaml +++ b/template.yaml @@ -9,7 +9,7 @@ Description: > Globals: Function: Timeout: 300 - MemorySize: 1024 + MemorySize: 600 Resources: HelloWorldFunction: