Skip to content

Commit 64125e1

Browse files
committed
Changed timing information to print on new line
Addresses the issue with the timing information overwriting the output discussed in #10 and sets up changes in #11.
1 parent 58e0bf4 commit 64125e1

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
=========
44

5+
v1.0.6 (30-06-2014)
6+
-------------------
7+
8+
- Moved timing information to separate line from problem output
9+
10+
511
v1.0.5 (30-06-2014)
612
-------------------
713

EulerPy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"""
44

55
__author__ = 'Kevin Yap'
6-
__version__ = '1.0.5'
6+
__version__ = '1.0.6'
77
__license__ = 'MIT License'

EulerPy/euler.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def verify_answer(problem):
9595

9696
# Calculate the wall time and format the output
9797
wall_time = wall_end - wall_start
98-
time_info = ' (time elapsed: {0})'.format(format_time(wall_time))
98+
time_info = 'Time elapsed: {0}'.format(format_time(wall_time))
9999

100100
# Python 3 returns bytes; use a valid encoding like ASCII as the output
101101
# will fall in that range
@@ -116,20 +116,22 @@ def verify_answer(problem):
116116
try:
117117
if output[-1] == '\n':
118118
output = output[:-1]
119-
120-
# If there is still a newline, the output is multilined. Print the
121-
# first line of the output on a separate line from the "checking
122-
# against solution" message.
123-
if '\n' in output:
124-
output = '\n' + output
125-
126119
except IndexError:
127120
output = "[no output]"
128121

129-
is_correct = output.strip() == solution
130-
click.secho(
131-
output, bold=True, nl=False, fg=('green' if is_correct else 'red')
132-
)
122+
# If there is still a newline, the output is multilined. Print the
123+
# first line of the output on a separate line from the "checking
124+
# against solution" message. Additionally, a multi-line output is
125+
# not going to be correct, so skip the solution check.
126+
if '\n' in output:
127+
# Multi-line output
128+
is_correct = False
129+
click.secho('\n' + output, bold=True, fg='red')
130+
else:
131+
is_correct = output.strip() == solution
132+
fg_colour = 'green' if is_correct else 'red'
133+
click.secho(output, bold=True, fg=fg_colour)
134+
133135
click.secho(time_info, fg='cyan')
134136
return is_correct
135137

0 commit comments

Comments
 (0)