Skip to content

Commit

Permalink
Fix res_printer in python
Browse files Browse the repository at this point in the history
  • Loading branch information
metopa committed Mar 17, 2018
1 parent 26ea636 commit 197a470
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
8 changes: 6 additions & 2 deletions epi_judge_python/interval_add.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import functools

from test_framework.test_failure import PropertyName
from test_framework.test_utils import enable_executor_hook

Interval = collections.namedtuple('Interval', ('left', 'right'))
Expand All @@ -19,11 +20,14 @@ def add_interval_wrapper(executor, disjoint_intervals, new_interval):
Interval(*new_interval)))


def res_printer(expected, result):
def res_printer(prop, value):
def fmt(x):
return [[e[0], e[1]] for e in x] if x else None

return fmt(expected), fmt(result)
if prop in (PropertyName.EXPECTED, PropertyName.RESULT):
return fmt(value)
else:
return value


from sys import exit
Expand Down
9 changes: 7 additions & 2 deletions epi_judge_python/rectangle_intersection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import collections

from test_framework.test_failure import PropertyName

Rectangle = collections.namedtuple('Rectangle', ('x', 'y', 'width', 'height'))


Expand All @@ -12,11 +14,14 @@ def intersect_rectangle_wrapper(R1, R2):
return intersect_rectangle(Rectangle(*R1), Rectangle(*R2))


def res_printer(expected, result):
def res_printer(prop, value):
def fmt(x):
return [x[0], x[1], x[2], x[3]] if x else None

return fmt(expected), fmt(result)
if prop in (PropertyName.EXPECTED, PropertyName.RESULT):
return fmt(value)
else:
return value


from sys import exit
Expand Down
8 changes: 6 additions & 2 deletions epi_judge_python/road_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import functools

from test_framework.test_utils import enable_executor_hook
from test_framework.test_failure import PropertyName

HighwaySection = collections.namedtuple('HighwaySection',
('x', 'y', 'distance'))
Expand All @@ -20,11 +21,14 @@ def find_best_proposals_wrapper(executor, H, P, n):
return executor.run(functools.partial(find_best_proposals, H, P, n))


def res_printer(expected, result):
def res_printer(prop, value):
def fmt(x):
return [x[0], x[1], x[2]] if x else None

return fmt(expected), fmt(result)
if prop in (PropertyName.EXPECTED, PropertyName.RESULT):
return fmt(value)
else:
return value


from sys import exit
Expand Down
9 changes: 7 additions & 2 deletions epi_judge_python/search_for_min_max_in_array.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import collections

from test_framework.test_failure import PropertyName

MinMax = collections.namedtuple('MinMax', ('smallest', 'largest'))


Expand All @@ -8,11 +10,14 @@ def find_min_max(A):
return MinMax(0, 0)


def res_printer(expected, result):
def res_printer(prop, value):
def fmt(x):
return 'min: {}, max: {}'.format(x[0], x[1]) if x else None

return fmt(expected), fmt(result)
if prop in (PropertyName.EXPECTED, PropertyName.RESULT):
return fmt(value)
else:
return value


from sys import exit
Expand Down
9 changes: 7 additions & 2 deletions epi_judge_python/search_for_missing_element.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import collections

from test_framework.test_failure import PropertyName

DuplicateAndMissing = collections.namedtuple('DuplicateAndMissing',
('duplicate', 'missing'))

Expand All @@ -9,11 +11,14 @@ def find_duplicate_missing(A):
return DuplicateAndMissing(0, 0)


def res_printer(expected, result):
def res_printer(prop, value):
def fmt(x):
return 'duplicate: {}, missing: {}'.format(x[0], x[1]) if x else None

return fmt(expected), fmt(result)
if prop in (PropertyName.EXPECTED, PropertyName.RESULT):
return fmt(value)
else:
return value


from sys import exit
Expand Down
11 changes: 6 additions & 5 deletions epi_judge_python/test_framework/test_utils_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ def print_failed_test(param_names, arguments, test_failure, res_printer):
print_std_out_colored(ConsoleColor.FG_YELLOW, '\nFailure info\n')

for prop in properties:
if res_printer is not None:
value = res_printer(prop.raw_name(), prop.value())
else:
value = prop.value()
print('\t', end='')
print_std_out_colored(ConsoleColor.FG_YELLOW, prop.name())
print(': {}{}'.format(gen_spaces(max_col_size - len(prop.name())),
prop.value()))

# TODO Implement res_printer logic
# (expected, result) = res_printer(expected, result)
print(': {}{}'.format(
gen_spaces(max_col_size - len(prop.name())), value))


def print_post_run_stats(tests_passed, total_tests, durations):
Expand Down

0 comments on commit 197a470

Please sign in to comment.