Skip to content

Commit

Permalink
# Sum of Triangular Numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 20, 2024
1 parent 4237e27 commit b63ab12
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
8 changes: 4 additions & 4 deletions kyu_7/sum_of_triangular_numbers/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Sum of Triangular Numbers

Your task is to return the sum of Triangular Numbers
Your task is to return the sum of `Triangular Numbers`
up-to-and-including the `nth` Triangular Number.

Triangular Number: "any of the series of numbers (1, 3, 6, 10, 15, etc.)
obtained by continued summation of the natural numbers 1, 2, 3, 4, 5, etc."
Triangular Number: "any of the series of numbers `(1, 3, 6, 10, 15, etc.)`
obtained by continued summation of the natural numbers `1, 2, 3, 4, 5,` etc."

> `[01]`
>
Expand All @@ -20,6 +20,6 @@ obtained by continued summation of the natural numbers 1, 2, 3, 4, 5, etc."
e.g. If `4` is given: `1 + 3 + 6 + 10 = 20`.

Triangular Numbers cannot be negative so return 0 if a negative number is given.
`Triangular Numbers` cannot be negative so return `0` if a negative number is given.

[Source](https://www.codewars.com/kata/580878d5d27b84b64c000b51)
1 change: 1 addition & 0 deletions kyu_7/sum_of_triangular_numbers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Sum of Triangular Numbers."""
7 changes: 4 additions & 3 deletions kyu_7/sum_of_triangular_numbers/sum_triangular_numbers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""
Solution for -> Sum of Triangular Numbers
Solution for -> Sum of Triangular Numbers.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def sum_triangular_numbers(n: int) -> int:
"""
returns the sum of Triangular Numbers
up-to-and-including the nth Triangular Number.
Return the sum of Triangular Numbers.
:param n:
:return:
"""
Expand Down
39 changes: 21 additions & 18 deletions kyu_7/sum_of_triangular_numbers/test_sum_triangular_numbers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Sum of Triangular Numbers
Test for -> Sum of Triangular Numbers.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand Down Expand Up @@ -28,14 +29,12 @@
url='https://www.codewars.com/kata/580878d5d27b84b64c000b51',
name='Source/Kata')
class SumTriangularNumbersTestCase(unittest.TestCase):
"""
Testing 'sum_triangular_numbers' function
"""
"""Testing 'sum_triangular_numbers' function."""

def test_sum_triangular_numbers_negative_numbers(self):
"""
Testing 'sum_triangular_numbers' function
with negative numbers
Testing 'sum_triangular_numbers' function with negative numbers.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -44,8 +43,9 @@ def test_sum_triangular_numbers_negative_numbers(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-msg=R0801
Expand All @@ -63,17 +63,18 @@ def test_sum_triangular_numbers_negative_numbers(self):

def test_sum_triangular_numbers_zero(self):
"""
Testing 'sum_triangular_numbers' function
with zero as an input
Testing 'sum_triangular_numbers' function with zero as an input.
:return:
"""
# pylint: disable-msg=R0801
allure.dynamic.title("Testing 'sum_triangular_numbers' with zero")
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-msg=R0801
Expand All @@ -95,8 +96,9 @@ def test_sum_triangular_numbers_positive_numbers(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-msg=R0801
Expand All @@ -116,8 +118,8 @@ def test_sum_triangular_numbers_positive_numbers(self):

def test_sum_triangular_numbers_big_number(self):
"""
Testing 'sum_triangular_numbers' function
with big number as an input
Testing 'sum_triangular_numbers' function with big number as an input.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -126,8 +128,9 @@ def test_sum_triangular_numbers_big_number(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-msg=R0801
Expand Down

0 comments on commit b63ab12

Please sign in to comment.