aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2020-03-27 11:15:21 +0100
committerLubos Kolouch <lubos@kolouch.net>2020-03-27 11:15:21 +0100
commitf10c5f37aa721630216911f71471f775c91cda8b (patch)
tree5740606bba1f4c5c57f5eb941f7e68ffbc5f5ad3
parent4ff4b90220ffc86ea757a40a704d5c904a0df6c8 (diff)
downloadperlweeklychallenge-club-f10c5f37aa721630216911f71471f775c91cda8b.tar.gz
perlweeklychallenge-club-f10c5f37aa721630216911f71471f775c91cda8b.tar.bz2
perlweeklychallenge-club-f10c5f37aa721630216911f71471f775c91cda8b.zip
Style cleanups
-rw-r--r--challenge-053/lubos-kolouch/python/ch_1.py (renamed from challenge-053/lubos-kolouch/python/ch-1.py)27
-rw-r--r--challenge-053/lubos-kolouch/python/ch_2.py (renamed from challenge-053/lubos-kolouch/python/ch-2.py)30
2 files changed, 43 insertions, 14 deletions
diff --git a/challenge-053/lubos-kolouch/python/ch-1.py b/challenge-053/lubos-kolouch/python/ch_1.py
index 843c17a699..63edffc377 100644
--- a/challenge-053/lubos-kolouch/python/ch-1.py
+++ b/challenge-053/lubos-kolouch/python/ch_1.py
@@ -1,36 +1,44 @@
#!/usr/bin/env python
+""" PerlWeeklyChallenge 53"""
import numpy as np
import pytest
class ArrRotator:
+ """ Rotator class for rotating the array"""
def __init__(self):
self.arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
+ self.degree = 0
- def check_degree(self, degree: int):
- if degree not in (90, 180, 270):
+ def check_degree(self):
+ """ check if the degree is valid"""
+ if self.degree not in (90, 180, 270):
raise ValueError('degree must be 90, 180 or 270')
def rotate_arr(self, degree: int):
- self.check_degree(degree)
+ """do the rotation"""
+
+ self.degree = degree
+ self.check_degree()
result_arr = self.arr
- for i in range(degree // 90):
+ for _ in range(degree // 90):
result_arr = np.rot90(result_arr, -1)
return result_arr
class RotatorTest:
- # TESTS
+ """Run the tests"""
def __init__(self):
self.rotator = ArrRotator()
def do_tests(self):
+ """ Run the tests for 90, 180, 270 degrees """
assert np.alltrue(self.rotator.rotate_arr(degree=90)
== [[7, 4, 1], [8, 5, 2], [9, 6, 3]])
@@ -39,10 +47,11 @@ class RotatorTest:
assert np.alltrue(self.rotator.rotate_arr(degree=270)
== [[3, 6, 9], [2, 5, 8], [1, 4, 7]])
with pytest.raises(ValueError):
- rotator.rotate_arr(degree=222)
+ self.rotator.rotate_arr(degree=222)
-if __name__ == "__main__":
+def main():
+ """ Run the program and tests """
rotator = ArrRotator()
print('Original array:')
@@ -58,3 +67,7 @@ if __name__ == "__main__":
tester = RotatorTest()
tester.do_tests()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/challenge-053/lubos-kolouch/python/ch-2.py b/challenge-053/lubos-kolouch/python/ch_2.py
index ebde8125fc..1cf753ed70 100644
--- a/challenge-053/lubos-kolouch/python/ch-2.py
+++ b/challenge-053/lubos-kolouch/python/ch_2.py
@@ -1,48 +1,64 @@
#!/usr/bin/env python
+""" PerlWeeklyChallenge 053"""
from itertools import permutations
class VowelString:
+ """ Produce all valid permutations"""
- def check_valid(self, permutation):
+ def __init__(self):
+ self.permutation = ''
+
+ def check_valid(self):
+ """ Check if given permutation is valid"""
ok_rules = ['ae', 'ai', 'ei', 'ia', 'ie',
'io', 'iu', 'oa', 'ou', 'uo', 'ue']
- for x, item in enumerate(permutation[:-1]):
- if item + permutation[x+1] not in ok_rules:
+ for item_count, item in enumerate(self.permutation[:-1]):
+ if item + self.permutation[item_count+1] not in ok_rules:
return 0
return 1
- def get_permutations(self, count: int):
+ def get_permutations(self, count: int):
+ """ process all possible permutations"""
wovels = ['a', 'e', 'i', 'o', 'u']
result = []
for perm in permutations(wovels, count):
- if self.check_valid(perm):
+ self.permutation = perm
+ if self.check_valid():
result.append(perm)
- return(result)
+ return result
class TestVowelString:
+ """Test for the VowelString method"""
def __init__(self):
self.vow = VowelString()
def do_tests(self):
+ """Run the tests"""
assert len(self.vow.get_permutations(1)) == 0
assert len(self.vow.get_permutations(2)) == 11
-if __name__ == "__main__":
+def main():
+ """Main method"""
+
vowcomb = VowelString()
print(vowcomb.get_permutations(2))
vowtester = TestVowelString()
vowtester.do_tests()
+
+
+if __name__ == "__main__":
+ main()