Example #1
0

def three_ok(result):
    assert result[3] == 'trzy'


def four_ok(result):
    assert result[4] == 4


def five_ok(result):
    assert result[5] == 'pięć'


def result_ok(result):
    expected_list = []
    for i in range(1000):
        if i % 3 == 0 and i % 5 == 0:
            expected_list.append('trzypięć')
        elif i % 3 == 0:
            expected_list.append('trzy')
        elif i % 5 == 0:
            expected_list.append('pięć')
        else:
            expected_list.append(i)
    assert result == expected_list


assignment = Assignment('zadanie1', 'zadanie1.py', 'result',
                        (fifteen_ok, three_ok, four_ok, five_ok, result_ok))
Example #2
0
def test1(result):
    assert type(result) == list


def length_ok(result):
    assert len(result) == 100


def first_ok(result):
    expected_result = list(range(1, 101)) + [1]
    assert result[0] == expected_result


def last_ok(result):
    expected_result = list(range(1, 101)) + [5050]
    assert result[-1] == expected_result


def result_ok(result):
    sum_list = [list(range(1, 101)) for x in range(100)]
    i = 0
    while i < 100:
        sum_list[i].append(sum(sum_list[i][:i + 1]))
        i += 1
    assert result == sum_list


assignment = Assignment('zadanie3', 'zadanie3.py', 'result',
                        (test1, length_ok, first_ok, last_ok, result_ok))
Example #3
0
    assert func([1, 2, 3], [4, 5, 6]) is None


def list_b_changed(func):
    """Czy lista podana jako drugi argument sie zmieniła? (czytanie treści zadania)"""
    x = [1, 2, 3]
    y = [4, 5, 6]
    func(x, y)
    assert y == [4, 5, 6, 3, 2, 1]


def list_a_not_changed(func):
    """Czy lista podana jako pierwszy argument zmieniła sie w trakcie zamiast zostać skopiowana?"""
    x = [1, 2, 3]
    y = [4, 5, 6]
    func(x, y)
    assert x == [1, 2, 3]


def list_a_empty(func):
    """Czy działa dla pustej listy w pierwszym argumencie?"""
    x = []
    y = [4, 5, 6]
    func(x, y)
    assert y == [4, 5, 6]


assignment = Assignment(
    'zadanie2', 'zadanie2.py', 'copy_reversed',
    (return_none, list_b_changed, list_a_not_changed, list_a_empty))
Example #4
0
def counted(f):
    def wrapped(*args, **kwargs):
        wrapped.calls += 1
        return f(*args, **kwargs)

    wrapped.calls = 0
    return wrapped


def recurrency_used(func, module, attr_name):
    """Czy rozwiazanie jest rekurencyjne (wywołuje samo siebie)?"""
    wrapped = counted(func)
    setattr(module, attr_name, wrapped)
    wrapped(5)
    setattr(module, attr_name, func)
    assert wrapped.calls > 1


assignment = Assignment(
    'zadanie4',
    'zadanie4.py',
    'factorial',
    (
        basic_test,
        test_one,
        test_zero,
        recurrency_used,
    )
)
Example #5
0
from homework_checker.base import Assignment

# Napisać kod tworzący listę list kolejnych elementów parzystych < 100 według
# schematu: [[0], [2], ... , [98]]. Wynikową listę przypisz na zmienną result.


def type_ok(result):
    assert type(result) == list


def length_ok(result):
    assert len(result) == 50


def second_ok(result):
    assert result[1] == [2]


def beforelast_ok(result):
    assert result[-2] == [96]


def test5(result):
    assert result == [[i] for i in range(100) if i % 2 == 0]


assignment = Assignment('zadanie2', 'zadanie2.py', 'result',
                        (type_ok, length_ok, second_ok, beforelast_ok, test5))
Example #6
0
    tempo_schodzenia = 3

    assert [32, 24, 13, 7,
            0] == func(lista_osob=lista_osob,
                       liczba_klatek_schodowych=liczba_klatek_schodowych,
                       liczba_osob_w_rzedzie=liczba_osob_w_rzedzie,
                       tempo_schodzenia=tempo_schodzenia)


def same_number_of_people_on_each_floor(func):
    """Czy dla jednakowej liczby osób na każdym piętrze dobre rozwiązanie."""
    lista_osob = [100] * 46
    liczba_klatek_schodowych = 2
    liczba_osob_w_rzedzie = 4
    tempo_schodzenia = 15

    assert [
        1260, 1232, 1204, 1176, 1148, 1120, 1092, 1064, 1036, 1008, 980, 952,
        924, 896, 868, 840, 812, 784, 756, 728, 700, 672, 644, 616, 588, 560,
        532, 504, 476, 448, 420, 392, 364, 336, 308, 280, 252, 224, 196, 168,
        140, 112, 84, 56, 28, 0
    ] == func(lista_osob=lista_osob,
              liczba_klatek_schodowych=liczba_klatek_schodowych,
              liczba_osob_w_rzedzie=liczba_osob_w_rzedzie,
              tempo_schodzenia=tempo_schodzenia)


assignment = Assignment('zadanie6', 'zadanie6.py', 'ewakuacja',
                        (ground_floor_only, test_from_assignment_description,
                         five_floors, same_number_of_people_on_each_floor))
Example #7
0
def length_ok(result):
    assert len(result) == 4


def types_ok(result):
    for k in result.keys():
        assert type(k) == str


def has_poniedzialek(result):
    assert 'Poniedziałek' in result


def result_ok(result):
    expected_result = {
        'Poniedziałek': 1,
        'Środa': 3,
        'Piątek': 5,
        'Niedziela': 7
    }
    assert result == expected_result


assignment = Assignment(
    'zadanie4',
    'zadanie4.py',
    'result',
    (length_ok, types_ok, has_poniedzialek, result_ok)
)
Example #8
0
    assert func(no_arg) == 10


def test_one_arg(func):
    """Czy pojedynczy argument działa? (fname=1)"""
    assert func(get_double_n, get_double_n=20) == 40


def test_multiple_args(func):
    """Czy lista argumentów działa? (fname=(1,2,3))"""
    assert func(get_product_of_three_values,
                get_product_of_three_values=(3, 4, 5)) == 60


def test_all_types_of_args(func):
    """Czy wszystkie typy argumentów przeszły (całkowity brak, pojedyncza wartość I lista wartości)?"""
    result = func(get_product_of_three_values,
                  no_arg,
                  get_double_n,
                  get_double_n=3,
                  get_product_of_three_values=(1, 2, 6))
    assert result == 28


assignment = Assignment('zadanie5', 'zadanie5.py', 'function_results_sum', (
    test_no_arg,
    test_one_arg,
    test_multiple_args,
    test_all_types_of_args,
))
Example #9
0
def power(n, p=2):
    return n**p


# testy poprawnosci


def power_5_3(func):
    """Czy podniesienie 5 do 3 potęgi zwraca 125?"""
    assert func(5, 3) == 125


def default_arg_2(func):
    """Czy drugi argument ma domyślną wartość 2?"""
    assert func(5) == 25


def p_zero(func):
    """Czy podniesienie do potęgi zerowej zwraca poprawny wynik (1)?"""
    assert func(5, 0) == 1


def n_zero(func):
    """Czy podnoszenie zera do potęgi działa poprawnie?"""
    assert func(0, 5) == 0


assignment = Assignment('zadanie1', 'zadanie1.py', 'power',
                        (power_5_3, default_arg_2, p_zero, n_zero))
Example #10
0
answer = {frozenset()}
for x in A:
    tmp = set()
    for y in answer:
        tmp.add(y | frozenset((x, )))
    answer |= tmp


def has_full(result):
    assert A in result


def has_empty(result):
    assert frozenset() in result


def is_set(result):
    assert type(result) == set


def length_ok(result):
    assert len(result) == len(answer)


def result_ok(result):
    assert result == answer


assignment = Assignment('zadanie5', 'zadanie5.py', 'result',
                        (has_full, has_empty, is_set, length_ok, result_ok))
Example #11
0
    assert isinstance(v5, Vector)
    assert 'Vector(3, 3, 3, 3)' == str(v4)


def comparison_with_list(cls):
    """Czy można porównywać z listą?"""
    looks_like_vector = [0, 1, 2, 3]
    v6 = Vector(0, 1, 2, 3)
    assert v6 == looks_like_vector
    assert looks_like_vector == v6


def check_inheritance_hierarchy(cls):
    """Czy klasa dziedziczy tylko i wyłącznie po typie 'object'?"""
    assert cls.mro() == [cls, object]


def check_len(cls):
    """Czy działa obliczanie długości wektora?"""
    v = cls(1, 2)
    assert 2 == len(v)
    v1 = cls(2, 4, 5.6, 7, 8)
    assert 5 == len(v1)


assignment = Assignment(
    'zadanie1', 'zadanie1.py', 'Vector',
    (has_getitem, getitem_works_properly, has_setitem, setitem_works_properly,
     iterate_over_elements, add_vectors, add_like_vectors,
     comparison_with_list, check_inheritance_hierarchy, check_len))
Example #12
0
#
# Args:
#    `elements_limit` - określa ilość zwróconych liczb. Jeśli `elements_limit` nie zostanie podane to generator ma być nieograniczony. Załóż, że jeżeli `elements_limit` będzie podane to zawsze będzie to int >= 0.


def test_10(func):
    assert list(func(10)) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]


def test_1(func):
    assert list(func(1)) == [0]


def test_0(func):
    assert list(func(0)) == []


def test_2(func):
    assert list(func(2)) == [0, 1]


def test_infitnite(func):
    ten = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
    no_limits = func()
    for x, y in zip(no_limits, ten):
        assert x == y


assignment = Assignment('zadanie3', 'zadanie3.py', 'fibonnacci',
                        (test_0, test_1, test_2, test_10, test_infitnite))
Example #13
0
    assert func() == [1]
    assert func() == [1]


def is_none_used(func, module):
    """Czy został wykorzystany `is None`?"""
    class stupid_list(list):
        def __eq__(self, other):
            # self == None returns True, but self is None doesn't
            return True

    module.list = stupid_list
    test_list = stupid_list([5, 6, 7])
    result = func(test_list)
    module.list = list
    assert [5, 6, 7, 1] == result


def empty_list_as_arg(func):
    """Czy podanie pustej listy działa poprawnie (wynik == [1])?"""
    test_list = []
    assert func(test_list) == [1]


assignment = Assignment('zadanie3', 'zadanie3.py', 'add_one', (
    basic_test,
    default_arg,
    is_none_used,
    empty_list_as_arg,
))
Example #14
0
def test_collatz_seq_invalid_start_0(func):
    test_invalid_start(func, 0)


def test_collatz_seq_invalid_start_negative(func):
    test_invalid_start(func, -12)


def test_collatz_seq_invalid_start_float(func):
    test_invalid_start(func, 2.0)


def test_collatz_seq_invalid_start_string(func):
    test_invalid_start(func, "111")


def test_collatz_seq_has_no_next_method(func):
    assert not hasattr(func, '__next__')


assignment = Assignment(
    'zadanie1', 'zadanie1.py', 'CollatzSeq',
    (test_collatz_seq_1, test_collatz_seq_2, test_collatz_seq_3,
     test_collatz_seq_12, test_collatz_seq_19, test_collatz_seq_27,
     test_collatz_seq_12346789, test_collatz_seq_invalid_start_0,
     test_collatz_seq_invalid_start_negative,
     test_collatz_seq_invalid_start_float,
     test_collatz_seq_invalid_start_string,
     test_collatz_seq_has_no_next_method))
Example #15
0
                src_files = os.listdir(src)
                for file_name in src_files:
                    full_file_name = os.path.join(src, file_name)
                    if (os.path.isfile(full_file_name)):
                        shutil.copy(full_file_name, tmpdirname)
                try:
                    os.chdir(tmpdirname)
                    func(*args, **kwargs)
                finally:
                    os.chdir(cwd)

        return wrapper

    return decorator


@run_in_clean_directory('../homework4/2a')
def test_basic(func, module, attr_name):
    assert 5 ==  func('stolice.csv', 'pytania.csv', 'odpowiedzi.csv')

@run_in_clean_directory('../homework4/2b')
def test_basic_2(func, module, attr_name):
    assert 4 ==  func('stolice.csv', 'pytania.csv', 'odpowiedzi.csv')

@run_in_clean_directory('../homework4/2c')
def test_everyting_bad(func, module, attr_name):
    assert 0 ==  func('stolice.csv', 'pytania.csv', 'odpowiedzi.csv')

assignment = Assignment('zadanie2', 'zadanie2.py', 'check_homework', (test_basic, test_basic_2,
                                                                      test_everyting_bad))
Example #16
0
    obrazek_2 = Picture(red=range(256), green=range(256), blue=range(256), width=64, height=4)
    obrazek_2.crop(0, 3, 1, 1)
    assert (192,) == obrazek_2.red()
    assert (192,) == obrazek_2.green()
    assert (192,) == obrazek_2.blue()

    # 2x3 near lower corner
    obrazek_2 = Picture(red=range(256), green=range(256), blue=range(256), width=64, height=4)
    obrazek_2.crop(1, 1, 2, 3)
    assert (65, 66, 129, 130, 193, 194) == obrazek_2.red()
    assert (65, 66, 129, 130, 193, 194) == obrazek_2.green()
    assert (65, 66, 129, 130, 193, 194) == obrazek_2.blue()

    # 15x15 wystający → 5x3 lower right corner
    obrazek_2 = Picture(red=range(256), green=range(256), blue=range(256), width=64, height=4)
    obrazek_2.crop(59, 1, 15, 15)
    assert (123, 124, 125, 126, 127, 187, 188, 189, 190, 191, 251, 252, 253, 254,
            255) == obrazek_2.red()
    assert (123, 124, 125, 126, 127, 187, 188, 189, 190, 191, 251, 252, 253, 254,
            255) == obrazek_2.green()
    assert (123, 124, 125, 126, 127, 187, 188, 189, 190, 191, 251, 252, 253, 254,
            255) == obrazek_2.blue()


assignment = Assignment(
    'zadanie4',
    'zadanie4.py',
    'Vector',
    (test_one_red_pixel, test_kwadrat_gradient, test_prostokat_gradient)
)
Example #17
0
    except module.InvalidDayError:
        pass
    else:
        assert False


def test_check_month(attribute, module, attr_name):
    try:
        attribute(21, 13, 2020)
    except module.InvalidMonthError:
        pass
    else:
        assert False


def test_check_year(attribute, module, attr_name):
    try:
        attribute(40, 5, 'hello')
    except module.InvalidYearError:
        pass
    else:
        assert False


assignment = Assignment(
    'zadanie1', 'zadanie1.py', 'Date',
    (has_date_error, has_invalid_year_error, has_invalid_month_error,
     has_invalid_day_error, invalid_year_error_bases_on_date_error,
     invalid_month_bases_on_date_error, invalid_day_error_bases_on_date_error,
     test_basic_usage, test_check_year, test_check_month, test_check_day))