2020-11-15 11:04:10 +01:00
|
|
|
#!/usr/bin/python3
|
2020-11-14 20:44:19 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Zadanie 104
|
|
|
|
|
|
|
|
Napisz funkcję `sum_from_one_to_n` zwracającą sume kwadratów liczb od 1 do `n`.
|
|
|
|
Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
|
|
|
|
|
|
|
|
NAME: sum_from_one_to_n
|
|
|
|
PARAMS: int
|
|
|
|
RETURN: int
|
|
|
|
POINTS: 1
|
|
|
|
"""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
from Task104 import sum_from_one_to_n
|
|
|
|
|
|
|
|
class Task104Test(unittest.TestCase):
|
|
|
|
"""Testy do zadania 104"""
|
|
|
|
|
|
|
|
def test_special_cases(self):
|
|
|
|
"""Testy przypadków szczególnych."""
|
|
|
|
self.assertEqual(sum_from_one_to_n(-100), 0)
|
|
|
|
self.assertEqual(sum_from_one_to_n(-1), 0)
|
|
|
|
self.assertEqual(sum_from_one_to_n(0), 0)
|
|
|
|
self.assertEqual(sum_from_one_to_n(1), 1)
|
|
|
|
self.assertEqual(sum_from_one_to_n(2), 5)
|
|
|
|
|
|
|
|
def test_regular(self):
|
|
|
|
"""Testy dla kilku liczb"""
|
|
|
|
self.assertEqual(sum_from_one_to_n(3), 14)
|
|
|
|
self.assertEqual(sum_from_one_to_n(4), 30)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|