From 95733aa1aab7d109ec49ec45a774ec2adc7f1951 Mon Sep 17 00:00:00 2001 From: s45168 <123@123.as> Date: Sun, 19 Nov 2017 15:44:41 +0100 Subject: [PATCH] test --- homework/task07.py | 22 ++++++++++++++++++++++ homework/task08.py | 24 ++++++++++++++++++++++++ homework/task09.py | 26 ++++++++++++++++++++++++++ homework/task10.py | 26 ++++++++++++++++++++++++++ homework/task11.py | 26 ++++++++++++++++++++++++++ labs02/task01.py | 2 +- labs02/task02.py | 8 +++++++- labs02/task03.py | 7 +++++++ labs02/test_task.py | 1 + 9 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 homework/task07.py create mode 100644 homework/task08.py create mode 100644 homework/task09.py create mode 100644 homework/task10.py create mode 100644 homework/task11.py diff --git a/homework/task07.py b/homework/task07.py new file mode 100644 index 0000000..80cbd37 --- /dev/null +++ b/homework/task07.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Napisz funkcję char_sum, która dla zadanego łańcucha zwraca +sumę kodów ASCII znaków. +""" +def char_sum(text): + pass + +def tests(f): + inputs = [["this is a string"], ["this is another string"]] + outputs = [1516, 2172] + + for input, output in zip(inputs, outputs): + if f(*input) != output: + return "ERROR: {}!={}".format(f(*input), output) + break + return "TESTS PASSED" + +if __name__ == "__main__": + print(tests(char_sum)) diff --git a/homework/task08.py b/homework/task08.py new file mode 100644 index 0000000..252b10d --- /dev/null +++ b/homework/task08.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Napisz funkcję sum_div35(n), która zwraca sumę wszystkich liczb podzielnych +przez 3 lub 5 mniejszych niż n. +""" + +def sum_div35(n): + pass + +def tests(f): + inputs = [[10], [100], [3845]] + outputs = [23, 2318, 3446403] + + for input, output in zip(inputs, outputs): + if f(*input) != output: + return "ERROR: {}!={}".format(f(*input), output) + break + return "TESTS PASSED" + +if __name__ == "__main__": + print(tests(sum_div35)) + diff --git a/homework/task09.py b/homework/task09.py new file mode 100644 index 0000000..9045054 --- /dev/null +++ b/homework/task09.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Napisz funkcję leet_speak, która podmienia w podanym napisie niektóre litery +na podobnie wyglądające cyfry: 'e' na '3', 'l' na '1', 'o' na '0', 't' na '7'. +Np. leet('leet') powinno zwrócić '1337'. +""" + + +def leet_speak(text): + pass + + +def tests(f): + inputs = [['leet'], ['do not want']] + outputs = ['1337', 'd0 n07 wan7'] + + for input, output in zip(inputs, outputs): + if f(*input) != output: + return "ERROR: {}!={}".format(f(*input), output) + break + return "TESTS PASSED" + +if __name__ == "__main__": + print(tests(leet_speak)) diff --git a/homework/task10.py b/homework/task10.py new file mode 100644 index 0000000..58d40d2 --- /dev/null +++ b/homework/task10.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +""" +Napisz funkcję pokemon_speak, która zamienia w podanym napisie co drugą literę +na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'. +""" + + +def pokemon_speak(text): + pass + + +def tests(f): + inputs = [['pokemon'], ['do not want'], ['POKEMON']] + outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON'] + + for input, output in zip(inputs, outputs): + if f(*input) != output: + return "ERROR: {}!={}".format(f(*input), output) + break + return "TESTS PASSED" + +if __name__ == "__main__": + print(tests(pokemon_speak)) diff --git a/homework/task11.py b/homework/task11.py new file mode 100644 index 0000000..7d36767 --- /dev/null +++ b/homework/task11.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +""" +Napisz funkcję common_chars(string1, string2), która zwraca alfabetycznie +uporządkowaną listę wspólnych liter z lańcuchów string1 i string2. +Oba napisy będą składać się wyłacznie z małych liter. +""" + +def common_chars(string1, string2): + pass + + +def tests(f): + inputs = [["this is a string", "ala ma kota"]] + outputs = [['a', 't']] + + for input, output in zip(inputs, outputs): + if f(*input) != output: + return "ERROR: {}!={}".format(f(*input), output) + break + return "TESTS PASSED" + +if __name__ == "__main__": + print(tests(common_chars)) diff --git a/labs02/task01.py b/labs02/task01.py index 7c08c56..a1f4a72 100644 --- a/labs02/task01.py +++ b/labs02/task01.py @@ -8,7 +8,7 @@ która zawiera tylko elementy z list o parzystych indeksach. def even_elements(lista): pass - + return lista[::2] def tests(f): inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]] diff --git a/labs02/task02.py b/labs02/task02.py index a6d6321..4d04411 100644 --- a/labs02/task02.py +++ b/labs02/task02.py @@ -5,8 +5,14 @@ Napisz funkcję days_in_year zwracającą liczbę dni w roku (365 albo 366). """ -def days_in_year(days): +def days_in_year(year): pass + if year % 400 == 0: + return 366 + elif year % 4 == 0 and year % 100 != 0: + return 366 + else: + return 365 def tests(f): inputs = [[2015], [2012], [1900], [2400], [1977]] diff --git a/labs02/task03.py b/labs02/task03.py index a1c3a85..041c6d5 100644 --- a/labs02/task03.py +++ b/labs02/task03.py @@ -11,12 +11,18 @@ litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak jak 'set', która przechowuje elementy bez powtórzeń.) """ +text = "this is a string , which i will use for string testing" +vocab = [',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'] def oov(text, vocab): pass + temp_text=text.split(' ') + temp_vocab=vocab.split(' ') + +""" def tests(f): inputs = [("this is a string , which i will use for string testing", [',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])] @@ -30,3 +36,4 @@ def tests(f): if __name__ == "__main__": print(tests(oov)) +""" \ No newline at end of file diff --git a/labs02/test_task.py b/labs02/test_task.py index 5879768..5df85d2 100755 --- a/labs02/test_task.py +++ b/labs02/test_task.py @@ -7,6 +7,7 @@ def suma(a, b): Napisz funkcję, która zwraca sumę elementów. """ pass + return a + b def tests(f): inputs = [(2, 3), (0, 0), (1, 1)]