aboutsummaryrefslogtreecommitdiff
path: root/tests/test_api.py
diff options
context:
space:
mode:
authorPaul Harrison <paul@harrison.sh>2022-11-20 15:13:16 +0000
committerPaul Harrison <paul@harrison.sh>2022-12-15 16:02:14 +0000
commit9baafc80ed889c232587cf5d4cfaa2db44d1825a (patch)
tree13371c1220a8eabbc0932d30cc9475b98b984c3b /tests/test_api.py
parentb4ba284dcc20563b9b7dde770b7c9f67c6b25e76 (diff)
feat: Hand ranking API
Hand ranking API with a health check root endpoint and rank endpoint.
Diffstat (limited to 'tests/test_api.py')
-rw-r--r--tests/test_api.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
new file mode 100644
index 0000000..8d9768f
--- /dev/null
+++ b/tests/test_api.py
@@ -0,0 +1,67 @@
+import pytest
+from fastapi.testclient import TestClient
+
+from poker.api import app
+
+
+@pytest.fixture(scope="function")
+def client() -> TestClient:
+ return TestClient(app)
+
+
+def test_health_check(client: TestClient) -> None:
+ response = client.get("/")
+
+ assert response.status_code == 200
+ assert response.json() == "OK"
+
+
+@pytest.mark.parametrize(
+ "body,expected",
+ [
+ ("AH KH QH JH 10H", "royal flush: hearts"),
+ ("6H 7H 8H 9H 10H", "straight flush: 10-high hearts"),
+ ("AH AC AD AS KH", "four of a kind: ace"),
+ ("AH AC AD KS KH", "full house: ace over king"),
+ ("KC 10C 8C 7C 5C", "flush: clubs"),
+ ("10H 9C 8D 7S 6H", "straight: 10-high"),
+ ("AH AC AD KS QH", "three of a kind: ace"),
+ ("AH AC KD KS 7H", "two pair: ace and king"),
+ ("AH AC KD JS 7H", "pair: ace"),
+ ("AH KC QD 9S 7H", "high card: ace"),
+ ],
+ ids=[
+ "royal-flush",
+ "straight-flush",
+ "four-of-a-kind",
+ "full-house",
+ "flush",
+ "straight",
+ "three-of-a-kind",
+ "two-pair",
+ "pair",
+ "high-card",
+ ],
+)
+def test_rank(client: TestClient, body: str, expected: str) -> None:
+ response = client.post("/rank", json=body)
+
+ assert response.status_code == 200
+ assert response.json() == expected
+
+
+@pytest.mark.parametrize(
+ "body",
+ [
+ "AH KH QH JH",
+ "AH KH QH JH 99W",
+ ],
+ ids=[
+ "too-few",
+ "not-a-card",
+ ],
+)
+def test_rank_bad_input(client: TestClient, body: str) -> None:
+ response = client.post("/rank", json=body)
+
+ assert response.status_code != 200