Skip to content

Commit

Permalink
added float output comparison (3 decimal digits)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinXPN committed Jul 15, 2021
1 parent ac8ecef commit a7d14ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion hello_world/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob
import json
import subprocess
import zipfile
import json
from pathlib import Path
from threading import Timer

Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: >
Globals:
Function:
Timeout: 300
MemorySize: 1024
MemorySize: 600

Resources:
HelloWorldFunction:
Expand Down

0 comments on commit a7d14ee

Please sign in to comment.