Skip to content

Commit 316d7d2

Browse files
committed
Make code simpler
1 parent 9d5030a commit 316d7d2

18 files changed

+44
-70
lines changed

python/tests/bin/test_p0018.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_compute(self):
2626
test_patterns = [((max, test_data_1), '23'), ((max, test_data_2), '1074')]
2727

2828
for args, expected in test_patterns:
29-
with self.subTest('triangle size: {}'.format(len(args[1]))):
29+
with self.subTest(f'triangle size: {len(args[1])}'):
3030
self.assertEqual(expected, compute(*args))
3131

3232

python/tests/bin/test_p0022.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '871198282')]
9+
test_patterns = [('p022_names.txt', '871198282')]
1010

11-
fh = asset_file('p022_names.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p022_names.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

python/tests/bin/test_p0042.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '162')]
9+
test_patterns = [('p042_words.txt', '162')]
1010

11-
fh = asset_file('p042_words.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p042_words.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

python/tests/bin/test_p0054.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '376')]
9+
test_patterns = [('p054_poker.txt', '376')]
1010

11-
fh = asset_file('p054_poker.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p054_poker.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

python/tests/bin/test_p0059.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '129448')]
9+
test_patterns = [('p059_cipher.txt', '129448')]
1010

11-
fh = asset_file('p059_cipher.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p059_cipher.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

python/tests/bin/test_p0063.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_compute(self):
99

1010
for args, expected in test_patterns:
1111
with self.subTest('NONE'):
12-
self.assertEqual(expected, compute())
12+
self.assertEqual(expected, compute(*args))
1313

1414

1515
if __name__ == '__main__':

python/tests/bin/test_p0067.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '7273')]
9+
test_patterns = [('p067_triangle.txt', '7273')]
1010

11-
fh = asset_file('p067_triangle.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p067_triangle.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(max, fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

python/tests/bin/test_p0070.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_compute(self):
99

1010
for args, expected in test_patterns:
1111
with self.subTest('NONE'):
12-
self.assertEqual(expected, compute())
12+
self.assertEqual(expected, compute(*args))
1313

1414

1515
if __name__ == '__main__':

python/tests/bin/test_p0079.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '73162890')]
9+
test_patterns = [('p079_keylog.txt', '73162890')]
1010

11-
fh = asset_file('p079_keylog.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p079_keylog.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

python/tests/bin/test_p0081.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TestSolution(unittest.TestCase):
88
def test_compute(self):
9-
test_patterns = [((), '427337')]
9+
test_patterns = [('p081_matrix.txt', '427337')]
1010

11-
fh = asset_file('p081_matrix.txt')
12-
for args, expected in test_patterns:
13-
with self.subTest('data file: p081_matrix.txt'):
11+
for fname, expected in test_patterns:
12+
with asset_file(fname) as fh, self.subTest(f'data file: {fname}'):
1413
self.assertEqual(expected, compute(min, fh))
15-
fh.close()
1614

1715

1816
if __name__ == '__main__':

0 commit comments

Comments
 (0)