コード例 #1
0
#!/usr/bin/env python

import pytest
from tests.utils import not_implemented
from tasks.training import training

pytestmark = pytest.mark.skipif(
    not_implemented(training, {}, 0),
    reason="training(expression) not implemented, skipping tests.",
)


def test_basic():
    assert training([(100, 0)], 1) == 100
    assert training([(100, 0), (300, 0)], 1) == 300
    assert training([(10, 1), (30, 1), (20, 1)], 3) == 50


def test_more():
    assert training([(1, i) for i in range(100_000)], 100_000) == 100_000

    L = []

    for j in range(11):
        L += [(j, i) for i in range(100_000)]

    assert training(L, 100_000) == 1_000_000

    assert training([(j, 0) for j in range(100)], 1000) == sum(range(100))
コード例 #2
0
#!/usr/bin/env python

import pytest
from tests.utils import not_implemented
from tasks.signal_crossing import signal_crossing

pytestmark = pytest.mark.skipif(
    not_implemented(signal_crossing, [0], 0),
    reason="signal_crossing(expression) not implemented, skipping tests.",
)


def test_basic():
    assert signal_crossing([0.1, 0.2, 3, 4], 3) == 1
    assert signal_crossing([1, 2, 4, 0.1], 3.4) == 2
    assert signal_crossing([3, 2.3, 2.1, 2.1, 2.3, 3], 2.1) == 0
コード例 #3
0
#!/usr/bin/env python

import pytest
from tests.utils import not_implemented
from tasks.wifi_password import wifi_password

pytestmark = pytest.mark.skipif(
    # Skip all tests in this module if the function(s) are not implemented
    not_implemented(wifi_password, 0),
    reason="wifi_password(n) not implemented, skipping tests.",
)


def test_small_fib():
    assert wifi_password(7) == 13
    assert wifi_password(10) == 55
    assert wifi_password(0) == 0
    assert wifi_password(1) == 1
    assert wifi_password(15) == 610


@pytest.mark.timeout(5)
def test_medium_fib():
    assert wifi_password(40) == 102334155
    assert wifi_password(60) == 1548008755920


@pytest.mark.timeout(5)
def test_large_fib():
    fib_1000 = (
        "434665576869374564356885276750406258025646605173717804024817290895365554179"
コード例 #4
0
#!/usr/bin/env python

import pytest
from tests.utils import not_implemented
from tasks.marketing import marketing

pytestmark = pytest.mark.skipif(
    # Skip all tests in this module if the function(s) are not implemented
    not_implemented(marketing, 1, 1, 1),
    reason="marketing(expression) not implemented, skipping tests.",
)


def test_marketing():
    assert marketing(100, 10, 10) == "Ernst & Young"
    assert marketing(11, 2, 3) == "11"
    assert marketing(12, 2, 3) == "Ernst & Young"
    assert marketing(13, 2, 3) == "13"
    assert marketing(14, 2, 3) == "Ernst"
    assert marketing(15, 21, 31) == "15"
    assert marketing(15, 21, 5) == "Young"
コード例 #5
0
#!/usr/bin/env python

import pytest

from tests.utils import not_implemented
from tasks.exact_hours import exact_hours

pytestmark = pytest.mark.skipif(
    # Skip all tests in this module if the function(s) are not implemented
    not_implemented(exact_hours, [], 0),
    reason="exact_hours(numbers) not implemented, skipping tests.",
)


def test_simple_lists():
    assert exact_hours([0, 1, 2, 3, 4], 0)
    assert not exact_hours([15, 25, 35, 45], 16)
    assert exact_hours([1, 2, 3, 4, 5], 15)
    assert not exact_hours([2, 4, 8, 16, 32], 25)


@pytest.mark.timeout(10)
def test_long_lists():
    assert exact_hours([i for i in range(50)], 805)
    assert not exact_hours([1, 3, 8, 5, 6, 13, 19, 7, 11, 19, 58, 108], 259)
    assert exact_hours([1, 3, 8, 5, 6, 13, 19, 7, 11, 19, 58], 117)
    assert not exact_hours(
        [0, 4, 8, 12, 6, 13, 48, 7, 11, 19, 58, 18, 52, 2, 41], 294)
コード例 #6
0
#!/usr/bin/env python

import re
from tasks.matmul import transpose, matmul, submatrix, determinant, mul
import numpy
import pytest
from tests.utils import not_implemented


def str_to_array(s):
    return [
        list(map(int, re.findall(r"-?\s*\d+", row))) for row in s.split("\n")
    ]


@pytest.mark.skipif(not_implemented(matmul, [[0]], [[0]]),
                    reason="matmul(X, Y) not implemented")
class TestMatrixMultiplication:
    def test_simple_2x2_multiplication(self):
        X = [[1, 2], [3, 4]]
        Y = [[5, 6], [7, 8]]
        result = matmul(X, Y)
        assert result == [[19, 22], [43, 50]]

    def test_identity_2x2_returns_same_value(self):
        X = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
        Y = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        result = matmul(X, Y)
        assert result == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    def test_simple_4x4_multiplication(self):
コード例 #7
0
#!/usr/bin/env python

import pytest
from tests.utils import not_implemented
from tasks.pipes import num_connected_platforms

pytestmark = pytest.mark.skipif(
    # Skip all tests in this module if the function(s) are not implemented
    not_implemented(num_connected_platforms, [False], []),
    reason=
    "num_connected_platforms(expression) not implemented, skipping tests.",
)


def test_basic():
    assert num_connected_platforms([False, True], [(2, 1)]) == 1

    assert num_connected_platforms([False, True, True], [(1, 2), (2, 3)]) == 0

    assert num_connected_platforms([True, False, True], [(3, 2), (2, 1)]) == 2


def test_other():
    assert num_connected_platforms([False, False], [(1, 2), (2, 1)]) == 0

    assert num_connected_platforms([True, True], [(1, 2), (2, 1)]) == 2

    assert num_connected_platforms([True], []) == 1
コード例 #8
0
#!/usr/bin/env python

import pytest
from tests.utils import not_implemented
from tasks.lisp import is_valid_lisp

pytestmark = pytest.mark.skipif(
    # Skip all tests in this module if the function(s) are not implemented
    not_implemented(is_valid_lisp, ""),
    reason="is_valid_lisp(expression) not implemented, skipping tests.",
)


def test_simple_expressions():
    assert is_valid_lisp("")
    assert not is_valid_lisp("(")
    assert not is_valid_lisp(")))))(")
    assert is_valid_lisp("((()))")


def test_medium_expressions():
    assert is_valid_lisp("(w(h)(a)(t))")
    assert is_valid_lisp("(once(upon((a))((time)there)(was ) an) expression)")
    assert not is_valid_lisp("(r)((a))()))(g)(((n)(a)))()(r)")