aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/ppentchev/python/tests/unit/test_routes.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-08 11:04:11 +0100
committerGitHub <noreply@github.com>2024-09-08 11:04:11 +0100
commit7cc7c2044811d44820194e9b8e4ef92a0a80a497 (patch)
treefce71a8f9cf696b32d0d584eeb6a97f704d8c386 /challenge-285/ppentchev/python/tests/unit/test_routes.py
parentf914ae6a3f7212cd2083677a8134d9009960a5b0 (diff)
parent50445dbe3f83551244d858e5d2a0a0e1a90adf75 (diff)
downloadperlweeklychallenge-club-7cc7c2044811d44820194e9b8e4ef92a0a80a497.tar.gz
perlweeklychallenge-club-7cc7c2044811d44820194e9b8e4ef92a0a80a497.tar.bz2
perlweeklychallenge-club-7cc7c2044811d44820194e9b8e4ef92a0a80a497.zip
Merge pull request #10788 from ppentchev/pp-285-python
Add Peter Pentchev's Python solution to 285.
Diffstat (limited to 'challenge-285/ppentchev/python/tests/unit/test_routes.py')
-rw-r--r--challenge-285/ppentchev/python/tests/unit/test_routes.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/challenge-285/ppentchev/python/tests/unit/test_routes.py b/challenge-285/ppentchev/python/tests/unit/test_routes.py
new file mode 100644
index 0000000000..743e0d20d2
--- /dev/null
+++ b/challenge-285/ppentchev/python/tests/unit/test_routes.py
@@ -0,0 +1,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)