Skip to content

Commit

Permalink
Formatting decimal places #0
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 24, 2024
1 parent 625967a commit 7e6d0be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions kyu_8/formatting_decimal_places_0/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Formatting decimal places #0."""
46 changes: 21 additions & 25 deletions kyu_8/formatting_decimal_places_0/test_two_decimal_places.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Formatting decimal places #0
Test for -> Formatting decimal places #0.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -8,6 +9,7 @@

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_8.formatting_decimal_places_0.two_decimal_places \
import two_decimal_places
Expand All @@ -29,14 +31,21 @@
name='Source/Kata')
# pylint: enable=R0801
class TwoDecimalPlacesTestCase(unittest.TestCase):
"""
Testing two_decimal_places function
"""
"""Testing two_decimal_places function."""

def test_two_decimal_places(self):
@parameterized.expand([
(4.659725356,
4.66,
"didn't work for 4.659725356"),
(173735326.3783732637948948,
173735326.38,
"didn't work for 173735326.3783732637948948"),
(4.653725356,
4.65,
"didn't work for 4.653725356")])
def test_two_decimal_places(self, n, expected, msg):
"""
Testing two_decimal_places function
with various test inputs.
Testing two_decimal_places function with various test inputs.
Each number should be formatted that it is
rounded to two decimal places. You don't
Expand All @@ -50,25 +59,12 @@ def test_two_decimal_places(self):
allure.dynamic.severity(allure.severity_level.NORMAL)
allure.dynamic.description_html(
'<h3>Codewars badge:</h3>'
'<img src="https://www.codewars.com/users/myFirstCode'
'/badges/large">'
'<img src="'
'https://www.codewars.com/users/myFirstCode/badges/large'
'">'
'<h3>Test Description:</h3>'
"<p></p>")
# pylint: enable=R0801
with allure.step("Pass a number and verify the output"):
data: tuple = (
(4.659725356,
4.66,
"didn't work for 4.659725356"),
(173735326.3783732637948948,
173735326.38,
"didn't work for 173735326.3783732637948948"),
(4.653725356,
4.65,
"didn't work for 4.653725356"))

for n, expected, msg in data:
print_log(n=n, expected=expected)
self.assertEqual(expected,
two_decimal_places(n),
msg)
print_log(n=n, expected=expected)
self.assertEqual(expected, two_decimal_places(n), msg)
5 changes: 4 additions & 1 deletion kyu_8/formatting_decimal_places_0/two_decimal_places.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> Formatting decimal places #0
Solution for -> Formatting decimal places #0.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def two_decimal_places(n: float) -> float:
"""
Convert a number into decimal.
Each number should be formatted that it is
rounded to two decimal places. You don't
need to check whether the input is a valid
Expand Down

0 comments on commit 7e6d0be

Please sign in to comment.