1.3. Entry Test

1.3.1. Assignments

Code 1.4. Entry Test Assignment A
"""
* Assignment: About EntryTest Warmup
* Complexity: easy
* Lines of code: 1 lines
* Time: 2 min

English:
    1. Define variable `result` with value 1
    2. Run doctests - all must succeed

Polish:
    1. Zdefiniuj zmienną `result` z wartością 1
    2. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert result is not Ellipsis, \
    'Assign result to variable: `result` instead of Ellipsis `...`'
    >>> assert type(result) is int, \
    'Variable `result` has invalid type, should be int'

    >>> result
    1
"""

# int: with value 1
result = ...


Code 1.5. Entry Test Assignment B
"""
* Assignment: About EntryTest ListDict
* Complexity: easy
* Lines of code: 4 lines
* Time: 8 min

English:
    1. Define `result: list[dict]`:
    2. Convert `DATA` from `list[tuple]` to `list[dict]`
        a. key - name from the header
        b. value - numerical value or species name
    3. Run doctests - all must succeed

Polish:
    1. Zdefiniuj `result: list[dict]`:
    2. Przekonwertuj `DATA` z `list[tuple]` do `list[dict]`
        a. klucz - nazwa z nagłówka
        b. wartość - wartość numeryczna lub nazwa gatunku
    3. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert result is not Ellipsis, \
    'Assign result to variable: `result` instead of Ellipsis `...`'
    >>> assert type(result) is list, \
    'Result must be a list'
    >>> assert len(result) > 0, \
    'Result cannot be empty'
    >>> assert all(type(element) is dict for element in result), \
    'All elements in result must be a dict'

    >>> result  # doctest: +NORMALIZE_WHITESPACE
    [{'Sepal length': 5.8, 'Sepal width': 2.7, 'Petal length': 5.1, 'Petal width': 1.9, 'Species': 'virginica'},
     {'Sepal length': 5.1, 'Sepal width': 3.5, 'Petal length': 1.4, 'Petal width': 0.2, 'Species': 'setosa'},
     {'Sepal length': 5.7, 'Sepal width': 2.8, 'Petal length': 4.1, 'Petal width': 1.3, 'Species': 'versicolor'},
     {'Sepal length': 6.3, 'Sepal width': 2.9, 'Petal length': 5.6, 'Petal width': 1.8, 'Species': 'virginica'},
     {'Sepal length': 6.4, 'Sepal width': 3.2, 'Petal length': 4.5, 'Petal width': 1.5, 'Species': 'versicolor'},
     {'Sepal length': 4.7, 'Sepal width': 3.2, 'Petal length': 1.3, 'Petal width': 0.2, 'Species': 'setosa'}]
"""

DATA = [('Sepal length', 'Sepal width', 'Petal length', 'Petal width', 'Species'),
        (5.8, 2.7, 5.1, 1.9, 'virginica'),
        (5.1, 3.5, 1.4, 0.2, 'setosa'),
        (5.7, 2.8, 4.1, 1.3, 'versicolor'),
        (6.3, 2.9, 5.6, 1.8, 'virginica'),
        (6.4, 3.2, 4.5, 1.5, 'versicolor'),
        (4.7, 3.2, 1.3, 0.2, 'setosa')]


# list[dict]: converted DATA from list[tuple] to list[dict]
result = ...


Code 1.6. Entry Test Assignment C
"""
* Assignment: About EntryTest Endswith
* Complexity: medium
* Lines of code: 4 lines
* Time: 8 min

English:
    1. Define `result: set[str]`
    2. Iterate over `DATA`
    3. Append to `result` species with endings in `SUFFIXES`
    4. Run doctests - all must succeed

Polish:
    1. Zdefiniuj `result: set[str]`
    2. Iterując po `DATA`
    3. Dodaj do `result` nazwy gatunków z końcówkami w `SUFFIXES`
    4. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert result is not Ellipsis, \
    'Assign result to variable: `result` instead of Ellipsis `...`'
    >>> assert type(result) is set, \
    'Result must be a set'
    >>> assert len(result) > 0, \
    'Result cannot be empty'
    >>> assert all(type(element) is str for element in result), \
    'All elements in result must be a str'

    >>> sorted(result)
    ['setosa', 'virginica']
"""

DATA = [('Sepal length', 'Sepal width', 'Petal length', 'Petal width', 'Species'),
        (5.8, 2.7, 5.1, 1.9, {'virginica'}),
        (5.1, 3.5, 1.4, 0.2, {'setosa'}),
        (5.7, 2.8, 4.1, 1.3, {'versicolor'}),
        (6.3, 2.9, 5.6, 1.8, {'virginica'}),
        (6.4, 3.2, 4.5, 1.5, {'versicolor'}),
        (4.7, 3.2, 1.3, 0.2, {'setosa'}),
        (7.0, 3.2, 4.7, 1.4, {'versicolor'}),
        (7.6, 3.0, 6.6, 2.1, {'virginica'}),
        (4.6, 3.1, 1.5, 0.2, {'setosa'})]

SUFFIXES = ('ca', 'osa')

# set[str]: species names with word endings in `SUFFIXES`
result = ...


Code 1.7. Entry Test Assignment D
"""
* Assignment: About EntryTest File
* Complexity: hard
* Lines of code: 16 lines
* Time: 13 min

English:
    1. Skip comments (`#`) and empty lines
    2. Extract from each line: ip, host and protocol and add to `result: list[dict]`
    3. Each line must be a separate dict
    4. Merge host names with the same IP
    5. IPv4 protocol address is when dot (`.`) is in ip address
    6. `result` must be `list[dict]`
    7. Run doctests - all must succeed

Polish:
    1. Pomiń komentarze (`#`) i puste linie
    2. Wyciągnij z każdej linii: ip, host i protokół i dodaj do `result: list[dict]`
    3. Każda linia ma być osobnym słownikiem
    4. Scal nazwy hostów dla tego samego IP
    5. Protokół IPv4 jest gdy kropka (`.`) znajduje się w adresie
    6. `result` musi być `list[dict]`
    7. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert result is not Ellipsis, \
    'Assign result to variable: `result` instead of Ellipsis `...`'
    >>> assert len(result) > 0, \
    'Result cannot be empty'
    >>> assert type(result) is list, \
    'Variable `result` has invalid type, should be list'
    >>> assert all(type(x) is dict for x in result), \
    'All keys in `result` should be dict'
    >>> assert [x['ip'] for x in result].count('127.0.0.1') == 1, \
    'You did not merge hostnames for the same ip (127.0.0.1)'

    >>> result  # doctest: +NORMALIZE_WHITESPACE
    [{'ip': '127.0.0.1', 'hosts': ['localhost', 'astromatt'], 'protocol': 'ipv4'},
     {'ip': '10.13.37.1', 'hosts': ['nasa.gov', 'esa.int', 'roscosmos.ru'], 'protocol': 'ipv4'},
     {'ip': '255.255.255.255', 'hosts': ['broadcasthost'], 'protocol': 'ipv4'},
     {'ip': '::1', 'hosts': ['localhost'], 'protocol': 'ipv6'}]
"""

DATA = """
##
# `/etc/hosts` structure:
#   - IPv4 or IPv6
#   - Hostnames
 ##

127.0.0.1       localhost
127.0.0.1       astromatt
10.13.37.1      nasa.gov esa.int roscosmos.ru
255.255.255.255 broadcasthost
::1             localhost
"""

# list[dict]: keys: ip, hosts, protocol; merge hosts for the same ip address
#             protocol is "ipv4" when '.' is in address; use conditional expr.
result = ...