|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +mkdir -p tasks |
| 4 | + |
| 5 | +function write_task_and_test() { |
| 6 | + num=$1 |
| 7 | + name=$2 |
| 8 | + task_code=$3 |
| 9 | + test_code=$4 |
| 10 | + |
| 11 | + task_file="tasks/task_${num}_${name}.py" |
| 12 | + test_file="test_${num}_${name}.py" |
| 13 | + |
| 14 | + echo "# task_${num}_${name}.py" > "$task_file" |
| 15 | + echo -e "$task_code" >> "$task_file" |
| 16 | + |
| 17 | + echo "# test_${num}_${name}.py" > "$test_file" |
| 18 | + echo -e "$test_code" >> "$test_file" |
| 19 | +} |
| 20 | + |
| 21 | +write_task_and_test "36" "sum_nested_list" ' |
| 22 | +def sum_nested_list(nested: list) -> int: |
| 23 | + """ |
| 24 | + Sečte všechna čísla v (potenciálně zanořeném) seznamu. |
| 25 | + Nápověda: isinstance(), rekurze |
| 26 | + """ |
| 27 | +' ' |
| 28 | +import pytest |
| 29 | +from tasks.task_36_sum_nested_list import sum_nested_list |
| 30 | +
|
| 31 | +def test_sum_nested_list(): |
| 32 | + assert sum_nested_list([1, 2, [3, 4], 5]) == 15 |
| 33 | + assert sum_nested_list([]) == 0 |
| 34 | + assert sum_nested_list([[[1]], 2, [3, [4]]]) == 10 |
| 35 | + assert sum_nested_list([0, [0, [0]]]) == 0 |
| 36 | + assert sum_nested_list([10, [20, [30, [40]]]]) == 100 |
| 37 | + assert sum_nested_list([1, [2], 3, [4, [5, [6]]]]) == 21 |
| 38 | +' |
| 39 | + |
| 40 | + |
| 41 | +write_task_and_test "37" "longest_unique_substring" ' |
| 42 | +def longest_unique_substring(s: str) -> int: |
| 43 | + """ |
| 44 | + Vrátí délku nejdelší podposloupnosti bez opakujících se znaků. |
| 45 | + """ |
| 46 | +' ' |
| 47 | +import pytest |
| 48 | +from tasks.task_37_longest_unique_substring import longest_unique_substring |
| 49 | +
|
| 50 | +def test_longest_unique_substring(): |
| 51 | + assert longest_unique_substring("abcabcbb") == 3 |
| 52 | + assert longest_unique_substring("bbbbb") == 1 |
| 53 | + assert longest_unique_substring("pwwkew") == 3 |
| 54 | + assert longest_unique_substring("") == 0 |
| 55 | + assert longest_unique_substring("abcdef") == 6 |
| 56 | + assert longest_unique_substring("abccba") == 3 |
| 57 | + assert longest_unique_substring("abba") == 2 |
| 58 | + assert longest_unique_substring("tmmzuxt") == 5 |
| 59 | +' |
| 60 | + |
| 61 | +write_task_and_test "38" "matrix_transpose" ' |
| 62 | +def matrix_transpose(matrix: list[list[int]]) -> list[list[int]]: |
| 63 | + """ |
| 64 | + Vrátí transponovanou matici. |
| 65 | + """ |
| 66 | +' ' |
| 67 | +import pytest |
| 68 | +from tasks.task_38_matrix_transpose import matrix_transpose |
| 69 | +
|
| 70 | +def test_matrix_transpose(): |
| 71 | + assert matrix_transpose([[1,2],[3,4]]) == [[1,3],[2,4]] |
| 72 | + assert matrix_transpose([[1,2,3]]) == [[1],[2],[3]] |
| 73 | + assert matrix_transpose([[1],[2],[3]]) == [[1,2,3]] |
| 74 | + assert matrix_transpose([]) == [] |
| 75 | + assert matrix_transpose([[5]]) == [[5]] |
| 76 | + assert matrix_transpose([[1,2,3],[4,5,6]]) == [[1,4],[2,5],[3,6]] |
| 77 | +' |
| 78 | + |
| 79 | +write_task_and_test "39" "reverse_vowels" ' |
| 80 | +def reverse_vowels(s: str) -> str: |
| 81 | + """ |
| 82 | + Vrátí řetězec s přeházenými samohláskami v opačném pořadí. |
| 83 | + Ostatní znaky zůstávají na místě. |
| 84 | + """ |
| 85 | +' ' |
| 86 | +import pytest |
| 87 | +from tasks.task_39_reverse_vowels import reverse_vowels |
| 88 | +
|
| 89 | +def test_reverse_vowels(): |
| 90 | + assert reverse_vowels("hello") == "holle" |
| 91 | + assert reverse_vowels("leetcode") == "leotcede" |
| 92 | + assert reverse_vowels("aA") == "Aa" |
| 93 | + assert reverse_vowels("Python") == "Python" |
| 94 | + assert reverse_vowels("") == "" |
| 95 | + assert reverse_vowels("bcdfg") == "bcdfg" |
| 96 | + assert reverse_vowels("AEIOU") == "UOIEA" |
| 97 | + assert reverse_vowels("racecar") == "racecar" |
| 98 | +' |
| 99 | + |
| 100 | +write_task_and_test "40" "most_frequent" ' |
| 101 | +def most_frequent(items: list) -> any: |
| 102 | + """ |
| 103 | + Vrátí nejčastěji se vyskytující prvek v seznamu. |
| 104 | + """ |
| 105 | +' ' |
| 106 | +import pytest |
| 107 | +from tasks.task_40_most_frequent import most_frequent |
| 108 | +
|
| 109 | +def test_most_frequent(): |
| 110 | + assert most_frequent([1,1,2,2,2,3]) == 2 |
| 111 | + assert most_frequent(["a","b","a","a","c"]) == "a" |
| 112 | + assert most_frequent([True, False, True, True]) == True |
| 113 | + assert most_frequent([42]) == 42 |
| 114 | + assert most_frequent(["x", "y", "x", "z", "x"]) == "x" |
| 115 | + assert most_frequent([3,3,3,2,2,1]) == 3 |
| 116 | +' |
0 commit comments