Skip to content

Commit

Permalink
refactor: drop are_equal, just use ==
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Sep 1, 2023
1 parent 6833f1b commit 2d85bcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
13 changes: 6 additions & 7 deletions tests/primes-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from resource import prlimit, RLIMIT_NPROC, RLIMIT_NOFILE
from subprocess import PIPE, run

from utils import VALGRIND_COMMAND, are_equal, format_result, run_command
from utils import VALGRIND_COMMAND, format_result, run_command

TESTS = [
{
Expand Down Expand Up @@ -73,13 +73,12 @@ def run_test(binary_path, test_config, run_valgrind=False):
number = test_config['number']
valgrind_enabled = test_config['valgrind_enabled']

expected_lines = set(generate_primes(number))

expected_primes = set(generate_primes(number))
resource_msg = None

try:
result_lines, valgrind_report = test_primes(binary_path, number, run_valgrind and valgrind_enabled)
res = are_equal(expected_lines, result_lines)
result_primes, valgrind_report = test_primes(binary_path, number, run_valgrind and valgrind_enabled)
res = result_primes == expected_primes
except Exception as e:
resource_msg = f'Resource error - {e}'
res = False
Expand All @@ -91,8 +90,8 @@ def run_test(binary_path, test_config, run_valgrind=False):
return res

if not res:
diff_res = expected_lines ^ result_lines
if not (expected_lines <= result_lines):
diff_res = expected_primes ^ result_primes
if not (expected_primes <= result_primes):
# missing prime numbers in result
assertion_msg = f"""
Prime numbers missing:
Expand Down
8 changes: 1 addition & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ def color(text, color_name):
def format_result(result):
return color('OK', 'green') if result else color('FAIL', 'red')

def are_equal(expected, current):
# ^ symmetric difference operator
diff = expected ^ current

return len(diff) == 0

def run_command(args, input=None, run_valgrind=False, cwd=None):
if run_valgrind:
args = VALGRIND_COMMAND + args
Expand All @@ -33,4 +27,4 @@ def run_command(args, input=None, run_valgrind=False, cwd=None):
valgrind_report = None
errors = proc.stderr if proc.stderr != '' else None

return proc.stdout, valgrind_report, errors
return proc.stdout, valgrind_report, errors

0 comments on commit 2d85bcc

Please sign in to comment.