1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: BSD-2-Clause
"""Test the first task in Perl weekly challenge 285, "No Connection"."""
from __future__ import annotations
import dataclasses
import pytest
from perl_weekly_285 import defs
from perl_weekly_285 import routes
@dataclasses.dataclass(frozen=True)
class RoutesCase:
"""A test case for the "No Connection" task."""
routes: list[tuple[str, str]]
"""The routes to examine."""
expected: str
"""The leaf destination we expect to find."""
@pytest.mark.parametrize(
"tcase",
[
RoutesCase(
routes=[
("me", "you"),
],
expected="you",
),
RoutesCase(
routes=[
("here", "there"),
("here", "everywhere"),
("there", "everywhere"),
],
expected="everywhere",
),
RoutesCase(
routes=[("B", "C"), ("D", "B"), ("C", "A")],
expected="A",
),
],
)
def test_connection(*, tcase: RoutesCase) -> None:
"""Make sure we can find the leaf destination."""
assert routes.solve_no_connection(tcase.routes) == tcase.expected
@pytest.mark.parametrize(
"tcase",
[
RoutesCase(
routes=[
("here", "there"),
("here", "everywhere"),
],
expected="not really",
),
RoutesCase(
routes=[("me", "you"), ("you", "me")],
expected="not really",
),
],
)
def test_no_connection(*, tcase: RoutesCase) -> None:
"""Make sure we cannot find any leaf destination."""
with pytest.raises(defs.NoSolutionError):
routes.solve_no_connection(tcase.routes)
|