Skip to content

Commit 646bf8e

Browse files
author
boraxpr
committed
bite 153
1 parent f197849 commit 646bf8e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.idea/
44
**/__pycache__/
55
/143/README.md
6+
/153/README.md

153/rounding.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def round_up_or_down(transactions, up=True):
2+
"""Round the list of transactions passed in.
3+
If up=True (default) ronud up, else round down.
4+
Return a new list of rounded values
5+
"""
6+
values = []
7+
if up:
8+
for each in transactions:
9+
each = each + 1
10+
values.append(int(each))
11+
if not up:
12+
for each in transactions:
13+
values.append(int(each))
14+
return values
15+
16+
17+
# print(round_up_or_down(transactions=[1.1, 2.2, 3.2, 4.7], up=True))

153/test_rounding.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from rounding import round_up_or_down
4+
5+
transactions1 = [2.05, 3.55, 4.50, 10.76, 100.25]
6+
transactions2 = [1.55, 9.17, 5.67, 6.77, 2.33]
7+
8+
9+
@pytest.mark.parametrize("transactions, up_arg, expected", [
10+
(transactions1, True, [3, 4, 5, 11, 101]),
11+
(transactions1, False, [2, 3, 4, 10, 100]),
12+
(transactions2, True, [2, 10, 6, 7, 3]),
13+
(transactions2, False, [1, 9, 5, 6, 2]),
14+
])
15+
def test_round_up_or_down(transactions, up_arg, expected):
16+
assert round_up_or_down(transactions, up=up_arg) == expected

0 commit comments

Comments
 (0)