aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/ppentchev/python/tests/unit/test_routes.py
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-09-09 15:10:21 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-09-09 15:10:21 +0800
commit90e81fa7a4d4ba2eb482542cde3401f8c166adc7 (patch)
tree32574bfed25f9181a5281395f5dc3dd0321e0de4 /challenge-285/ppentchev/python/tests/unit/test_routes.py
parentd7a3db86265e08657df10663e50d63d87d6695d1 (diff)
parent3c67a5382758155040d6598a2fa01ca5fd6d25d9 (diff)
downloadperlweeklychallenge-club-90e81fa7a4d4ba2eb482542cde3401f8c166adc7.tar.gz
perlweeklychallenge-club-90e81fa7a4d4ba2eb482542cde3401f8c166adc7.tar.bz2
perlweeklychallenge-club-90e81fa7a4d4ba2eb482542cde3401f8c166adc7.zip
Merge remote-tracking branch 'upstream/master'
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)