41 lines
975 B
Python
41 lines
975 B
Python
|
#!/usr/bin/python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
"""
|
||
|
Zadanie 107
|
||
|
|
||
|
Napisz funkcję `list_squared(list)` zwracającą sumę kwadratów
|
||
|
zadanych liczb. Dla listy pustej powinna zostać zwrócona wartość zero.
|
||
|
|
||
|
NAME: list_squared
|
||
|
PARAMS: list
|
||
|
RETURN: obj
|
||
|
POINTS: 3
|
||
|
"""
|
||
|
|
||
|
import unittest
|
||
|
from Task107 import list_squared
|
||
|
|
||
|
class Task107Test(unittest.TestCase):
|
||
|
"""Testy do zadania 107"""
|
||
|
|
||
|
def test_simple(self):
|
||
|
"""Prosty test."""
|
||
|
self.assertEqual(list_squared([3, 0, -1, 2]), 14),
|
||
|
|
||
|
def test_empty(self):
|
||
|
"""Test na pustej liście."""
|
||
|
self.assertEqual(list_squared([]), 0),
|
||
|
|
||
|
def test_singleton(self):
|
||
|
"""Test na liście jednoelementowej."""
|
||
|
self.assertEqual(list_squared([-4]), 16)
|
||
|
|
||
|
def test_two_elements(self):
|
||
|
"""Test na liście dwuelementowej."""
|
||
|
self.assertEqual(list_squared([100, -100]), 20000)
|
||
|
self.assertEqual(list_squared([2, 10]), 104)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|