Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit c63de70

Browse files
committed
Fixed iss. #24 (#44)
1 parent 0ebf301 commit c63de70

File tree

13 files changed

+430
-296
lines changed

13 files changed

+430
-296
lines changed

src/bisearch/prefix.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@ class NotFound(Exception):
1717

1818

1919
def bisect_right(origin: List[str], search: str = "") -> int:
20-
"""Return the most right one index matching the search value
20+
"""
21+
Return the most right one index matching the search value
22+
23+
Current function implements common ``bisect_right`` algorithms.
24+
The search value represents prefix the string should starts with,
25+
that's why current string is trimmed before comparison operation.
2126
2227
:param origin: a list of strings
23-
:type origin: list[str]
28+
:type origin: list
2429
:param search: a prefix to search
2530
:type search: str
2631
2732
:return: the index after the last string starting with search prefix
2833
:rtype: int
2934
30-
:raise: NotFound
35+
:raise NotFound: if the searched value isn't in the list
3136
32-
Current function implements common ``bisect_right`` algorithms.
33-
The search value represents prefix the string should starts with,
34-
that's why current string is trimmed before comparison operation.
37+
Usage:
38+
39+
>>> data = ["apple", "apple", "banana", "banana", "cherry"]
40+
>>> assert bisect_right(data, "a") == 2
41+
>>> assert bisect_right(data, "b") == 4
42+
>>> assert bisect_right(data, "c") == 5
3543
3644
"""
3745

@@ -55,21 +63,29 @@ def bisect_right(origin: List[str], search: str = "") -> int:
5563

5664

5765
def bisect_left(origin: List[str], search: str = "") -> int:
58-
"""Return the most left one index matching the search value
66+
"""
67+
Return the most left one index matching the search value
68+
69+
Current function implements common ``bisect_left`` algorithms.
70+
The search value represents prefix the string should starts with,
71+
that's why current string is trimmed before comparison operation.
5972
6073
:param origin: a list of strings
61-
:type origin: list[str]
74+
:type origin: list
6275
:param search: a prefix to search
6376
:type search: str
6477
6578
:return: the index of the first string starting with search prefix
6679
:rtype: int
6780
68-
:raise: NotFound
81+
:raise NotFound: if the searched value isn't in the list
6982
70-
Current function implements common ``bisect_left`` algorithms.
71-
The search value represents prefix the string should starts with,
72-
that's why current string is trimmed before comparison operation.
83+
Usage:
84+
85+
>>> data = ["apple", "apple", "banana", "banana", "cherry"]
86+
>>> assert bisect_left(data, "a") == 0
87+
>>> assert bisect_left(data, "b") == 2
88+
>>> assert bisect_left(data, "c") == 4
7389
7490
"""
7591

@@ -93,15 +109,23 @@ def bisect_left(origin: List[str], search: str = "") -> int:
93109

94110

95111
def find_all(origin: List[str], search: str = "") -> List[str]:
96-
"""Return strings starting with prefix
112+
"""
113+
Return strings starting with prefix
97114
98115
:param origin: the list of strings
99-
:type origin: list[str]
116+
:type origin: list
100117
:param search: the prefix to search, defaults to empty string
101118
:type search: str
102119
103120
:return: the list of strings starting with the search prefix
104-
:rtype: list[str]
121+
:rtype: list
122+
123+
Usage:
124+
125+
>>> data = ["apple", "apple", "banana", "banana", "cherry"]
126+
>>> assert find_all(data, "a") == ["apple", "apple"]
127+
>>> assert find_all(data, "b") == ["banana", "banana"]
128+
>>> assert find_all(data, "c") == ["cherry"]
105129
106130
"""
107131

src/calc/func.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55

66

77
def get_factorial(number: int, /) -> int:
8-
"""Return the factorial value for a given number
8+
"""
9+
Return the factorial value for a given number
10+
11+
In mathematics the factorial is the product of all positive integers
12+
less than or equal to given number.
13+
E.g. 5! = 5 * 4! = 5 * 4 * 3 * 2 * 1 = 120.
14+
The value of 0! = 1 according to the convention of an empty product.
915
1016
:param number:
1117
:type number: int
1218
1319
:return: the factorial value
1420
:rtype: int
1521
16-
In mathematics the factorial is the product of all positive integers
17-
less than or equal to given number.
18-
E.g. 5! = 5 * 4! = 5 * 4 * 3 * 2 * 1 = 120.
19-
The value of 0! = 1 according to the convention of an empty product.
20-
21-
Usage examples:
22+
Usage:
2223
2324
>>> assert get_factorial(0) == 1
2425
>>> assert get_factorial(5) == 120
@@ -32,19 +33,20 @@ def get_factorial(number: int, /) -> int:
3233

3334

3435
def get_fibonacci_number(idx: int, /) -> int:
35-
"""Return a Fibonacci's sequence number at a specified index
36+
"""
37+
Return a Fibonacci's sequence number at a specified index
38+
39+
The Fibonacci number is a number from the Fibonacci sequence, in which
40+
each number is the sum of the two preceding ones. This sequence commonly
41+
starts from 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...
3642
3743
:param idx: a Fibonacci sequence index starting from 0
3844
:type idx: int
3945
4046
:return: a sequence's member
4147
:rtype: int
4248
43-
The Fibonacci number is a number from the Fibonacci sequence, in which
44-
each number is the sum of the two preceding ones. This sequence commonly
45-
starts from 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...
46-
47-
Usage examples:
49+
Usage:
4850
4951
>>> assert get_fibonacci_number(0) == 0
5052
>>> assert get_fibonacci_number(1) == 1
@@ -64,16 +66,25 @@ def get_fibonacci_number(idx: int, /) -> int:
6466

6567

6668
def get_fibonacci_number_nr(idx: int, /) -> int:
67-
"""Return a Fibonacci's sequence number at a specified index
69+
"""
70+
Return a Fibonacci's sequence number at a specified index
71+
72+
This function implements the non-recursive algorithm, which is more
73+
efficient, since it does not have multiple recursive calls.
6874
6975
:param idx: a Fibonacci sequence index starting from 0
7076
:type idx: int
7177
7278
:return: a sequence's member
7379
:rtype: int
7480
75-
This function implements the non-recursive algorithm, which is more
76-
efficient, since it does not have multiple recursive calls.
81+
Usage:
82+
83+
>>> assert get_fibonacci_number(0) == 0
84+
>>> assert get_fibonacci_number(1) == 1
85+
>>> assert get_fibonacci_number(2) == 1
86+
>>> assert get_fibonacci_number(3) == 2
87+
>>> assert get_fibonacci_number(4) == 3
7788
7889
"""
7990

@@ -91,7 +102,11 @@ def get_fibonacci_number_nr(idx: int, /) -> int:
91102

92103

93104
def get_sum_of_strings(number_1: str, number_2: str, /) -> str:
94-
"""Return the sum of two numbers of string type as string
105+
"""
106+
Return the sum of two numbers of string type as string
107+
108+
Valid input is a string of any length containing numeric characters from
109+
0 to 9. Empty strings are allowed as well and should be considered as 0.
95110
96111
:param number_1: first number
97112
:type number_1: str
@@ -101,10 +116,7 @@ def get_sum_of_strings(number_1: str, number_2: str, /) -> str:
101116
:return: the sum of two numbers
102117
:rtype: str
103118
104-
Valid input is a string of any length containing numeric characters from
105-
0 to 9. Empty strings are allowed as well and should be considered as 0.
106-
107-
Usage examples:
119+
Usage:
108120
109121
>>> assert get_sum_of_strings("123", "456") == "579"
110122
>>> assert get_sum_of_strings("099", "001") == "100"

src/chess/func.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@
1212

1313

1414
def within_board(position: Tuple[int, int]) -> bool:
15-
"""Check if position is within a chess board
15+
"""
16+
Check if position is within a chess board
1617
1718
:param position: a position to check
1819
:type position: tuple
1920
2021
:return: True if position is within a chess board, otherwise False
2122
:rtype: bool
2223
24+
Usage:
25+
26+
>>> assert within_board((2, 2)) is True
27+
>>> assert within_board((3, 3)) is True
28+
>>> assert within_board((4, 4)) is True
29+
>>> assert within_board((5, -5)) is False
30+
>>> assert within_board((-5, 5)) is False
31+
>>> assert within_board((5, 50)) is False
32+
2333
"""
2434

2535
position_x, position_y = position
@@ -29,7 +39,8 @@ def within_board(position: Tuple[int, int]) -> bool:
2939

3040
def filter_can_move(pieces: List[Piece],
3141
position: Tuple[int, int]) -> List[Piece]:
32-
"""Filter the list of chess piece
42+
"""
43+
Filter the list of chess piece
3344
3445
:param pieces: a list of chess pieces
3546
:type pieces: list

src/chess/piece.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414

1515
class Piece:
16-
"""Chess piece model
16+
"""
17+
Chess piece model
1718
1819
:ivar position: the position on a chess board
1920
:type position: tuple
@@ -25,12 +26,13 @@ class Piece:
2526
def __init__(self,
2627
is_white: bool = True,
2728
position: Tuple[int, int] = (0, 0)) -> None:
28-
"""Initialize instance
29+
"""
30+
Initialize instance
2931
3032
:param is_white: indicating if a piece is white. Defaults to True.
31-
:type is_white: bool
33+
:type is_white: bool, optional
3234
:param position: initial piece position. Defaults to (0, 0).
33-
:type position: tuple
35+
:type position: tuple, optional
3436
3537
"""
3638

@@ -48,7 +50,8 @@ def swap_color(self) -> None:
4850
self.is_white = not self.is_white
4951

5052
def set_position(self, position: Tuple[int, int]) -> None:
51-
"""Change piece position to a specified one
53+
"""
54+
Change piece position to a specified one
5255
5356
:param position: new position for a piece
5457
:type position: tuple
@@ -62,7 +65,8 @@ def set_position(self, position: Tuple[int, int]) -> None:
6265
logger.warning("Position %s is outside the board", position)
6366

6467
def can_move(self, position: Tuple[int, int]) -> bool:
65-
"""Check if a move to a specified position is valid
68+
"""
69+
Check if a move to a specified position is valid
6670
6771
:param position: a position to check
6872
:type position: tuple
@@ -75,7 +79,8 @@ def can_move(self, position: Tuple[int, int]) -> bool:
7579
raise NotImplementedError
7680

7781
def get_delta(self, position: Tuple[int, int]) -> Tuple[int, int]:
78-
"""Return the deltas between current position and the specified one
82+
"""
83+
Return the deltas between current position and the specified one
7984
8085
:param position: a position to calculate delta with
8186
:type position: tuple

src/chess/symbols.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
Chess pieces unicode symbols
3+
34
"""
45

56
WHITE_KING = chr(0x2654)

src/conv_store/models.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
class Product:
10-
"""Product model implementation
10+
"""
11+
Product model implementation
1112
1213
Instances of this class represent a product available for purchase.
1314
@@ -25,7 +26,8 @@ def __init__(self,
2526
price: int,
2627
unit: Union[int, float]
2728
) -> None:
28-
"""Initialize instance
29+
"""
30+
Initialize instance
2931
3032
:param name: product name
3133
:type name: str
@@ -158,16 +160,16 @@ def __iter__(self) -> Iterator[Tuple[Product, Union[int, float]]]:
158160
def remove_product(self,
159161
product: Product
160162
) -> Tuple[Product, Union[int, float]]:
161-
"""Remove product from a cart instance
162-
163+
"""
164+
Remove product from a cart instance
163165
164166
:param product: a product instance to add to cart
165167
:type product: :class: `Product`
166168
167169
:return: a shopping cart product/quantity entry
168170
:rtype: tuple
169171
170-
:raise: ValueError
172+
:raise ValueError: if the project isn't present in the shopping cart
171173
172174
"""
173175

@@ -216,16 +218,16 @@ def sub_product(self,
216218
product: Product,
217219
quantity: Union[int, float]
218220
) -> None:
219-
"""Subtract product from the shopping cart
221+
"""
222+
Subtract product from the shopping cart
220223
221224
If quantity value is less or equal to 0 the product is to be
222225
removed from the shopping cart
223226
224-
225227
:param product: a product instance to add to cart
226228
:type product: :class: `Product`
227229
:param quantity: a quantity of a product to add
228-
:type quantity: int or float
230+
:type quantity: int | float
229231
230232
"""
231233

0 commit comments

Comments
 (0)