diff --git a/README.md b/README.md index f2e8141..8448fda 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,100 @@ -# 014-higher_lower +# Higher Lower +A console game from Udemy's *100 Days of Code: The Complete Python Pro Bootcamp* +(day 14). Two Instagram accounts are shown. Guess which one has more followers. +Every right guess adds a point and the winner stays for the next round. A wrong +guess ends the game. + +``` +Compare A: Cristiano Ronaldo, a Footballer, from Portugal. + + _ __ +| | / /____ +| | / / ___/ +| |/ (__ ) +|___/____(_) + +Against B: Ariana Grande, a Musician and actress, from United States. +Who has more followers? Type 'A' or 'B': +``` + +- Python 3.13 or newer, no runtime dependencies. +- The function names follow the assignment: `format_data`, `check_answer`. +- Each account is shown once per game; if you get through all 50, you win. +- Follower counts are in millions and come from the assignment's data set. + +## Requirements + +- [Python](https://www.python.org/downloads/) 3.13 or newer +- Optional: [Doxygen](https://www.doxygen.nl/) to build the source documentation + +## Set up + +Create a local virtual environment in `.venv`, activate it, and upgrade `pip`. + +Windows (PowerShell): + +```powershell +python -m venv .venv +.venv\Scripts\Activate.ps1 +python -m pip install --upgrade pip +``` + +Windows (Git Bash), Linux and macOS: + +```bash +python -m venv .venv +source .venv/Scripts/activate # Linux/macOS: source .venv/bin/activate +python -m pip install --upgrade pip +``` + +The game itself needs nothing more. To run the tests and the code checks, install the +development tools: + +```bash +python -m pip install -e ".[dev]" +``` + +## Run the game + +```bash +python -m higher_lower +``` + +Type `A` or `B` and press Enter. Press Ctrl+C to quit. + +## Run the tests + +```bash +python -m pytest +``` + +Check the code style and types: + +```bash +python -m ruff check src tests +python -m ruff format --check src tests +python -m mypy src tests +``` + +## Build the source documentation + +The source uses Doxygen comments. The HTML output goes to `docs/doxygen/html`. + +```bash +doxygen Doxyfile +``` + +## Project layout + +| Path | Content | +| --- | --- | +| `src/higher_lower/` | The game: `game_logic.py` (pure functions), `game.py` (the loop), `game_data.py`, `art.py`, `constants.py` | +| `tests/` | pytest tests | +| `docs/` | Planning and review documents (business case, plan, milestones, use case) | +| `pyproject.toml` | Project configuration | +| `Doxyfile` | Doxygen configuration | + +## License + +GNU Affero General Public License v3.0. See [LICENSE](LICENSE). diff --git a/docs/artifact-registry.md b/docs/artifact-registry.md index d62dffc..dfb7b94 100644 --- a/docs/artifact-registry.md +++ b/docs/artifact-registry.md @@ -15,7 +15,7 @@ document of a type. `Primary File` may contain a glob (e.g. | SA | Stakeholder Analysis | docs/stakeholder-analysis.md | 002 | | PP | Project Plan | docs/project-plan.md | 002 | | MIL | Milestone / Gateway | docs/milestones/*.md | 005 | -| RC | SQA Review Record | docs/sqa/reviews/rc-*.md | 011 | +| RC | SQA Review Record | docs/sqa/reviews/rc-*.md | 013 | | TM | Traceability Matrix | docs/sqa/traceability-matrix.md | 002 | | UCD | Use Case Diagram | docs/use-case-diagram.md | 002 | | US | User Story | docs/user-stories.md | 002 | diff --git a/docs/milestones/mil-004-docs-release.md b/docs/milestones/mil-004-docs-release.md index 55cdc3c..9df86e0 100644 --- a/docs/milestones/mil-004-docs-release.md +++ b/docs/milestones/mil-004-docs-release.md @@ -4,12 +4,13 @@ | Key | Value | | --- | --- | | ID | MIL-004 | -| CrossReference | [BC-001], [PP-001] | +| CrossReference | [BC-001], [PP-001], [RC-011] | ## Version History | Date | Status | Author | Reviewer | Change | Commit | | --- | --- | --- | --- | --- | --- | -| 2026-10-04 | Proposed | Jens Tirsvad Nielsen | S01 | Initial version | [ddfe96f] | +| 2026-10-04 | Deprecated | Jens Tirsvad Nielsen | S01 | Initial version | [ddfe96f] | +| 2026-10-04 | Accepted | Jens Tirsvad Nielsen | S01 | Accepted after review RC-011 | [267e34f] | --- @@ -70,3 +71,5 @@ Decide whether the repository is ready to be shared with S02 and S03: documented [PP-001]: ../project-plan.md [MIL-003]: ./mil-003-console-game.md [ddfe96f]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/ddfe96ffa459d5e4b2e30d71bd53878aba2cfc5d +[RC-011]: ../sqa/reviews/rc-011-mil-004.md +[267e34f]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/267e34fc9f1fb9d76cc20032f3b09dc8e9dd82c7 diff --git a/docs/sqa/reviews/rc-011-mil-004.md b/docs/sqa/reviews/rc-011-mil-004.md new file mode 100644 index 0000000..eaf2a87 --- /dev/null +++ b/docs/sqa/reviews/rc-011-mil-004.md @@ -0,0 +1,46 @@ +# SQA Review Record: MIL-004 Documentation and release + +## Metadata +| Key | Value | +| --- | --- | +| ID | RC-011 | +| CrossReference | [MIL-004], [QC-MIL-001] | + +## Version History +| Date | Status | Author | Reviewer | Change | Commit | +| --- | --- | --- | --- | --- | --- | +| 2026-10-04 | Accepted | Jens Tirsvad Nielsen | S01 | Initial version | [267e34f] | + +--- + +## Artifact Under Review + +- Instance reviewed: [MIL-004] +- Checklist used: [QC-MIL-001] + +## Checklist Results + +| # | Criterion | Status | Evidence/Notes | +| --- | --- | --- | --- | +| 1 | A concrete deliverable is defined for every gate | Pass | README, Doxygen build, review records and a verified clean copy. | +| 2 | Explicit Go/No-Go criteria are stated for each gate | Pass | Six objectively checkable criteria. | +| 3 | Dependencies on other milestones are explicitly mapped (Optional) | Pass | Depends on MIL-003, with the reason. | +| 4 | Each milestone is traceable to a Business Case objective or KPI | Pass | O2, O4, O5. | +| 5 | Milestone owner and approving reviewer are identified | Pass | S01 and S01. | +| 6 | Milestone has a target date consistent with project constraints | Pass | 2026-10-14, the date in the BC-001 constraint. | + +## Overall Verdict + +Go — all criteria pass. Reviewer and author are both S01: the project has a single participant, so the framework's author/reviewer separation cannot be met. S01 accepted this deviation when requesting acceptance (2026-10-04). + +## Action Items + +| Action | Owner | Due | +| --- | --- | --- | +| None | — | — | + +--- + +[MIL-004]: ../../milestones/mil-004-docs-release.md +[QC-MIL-001]: ../../../framework/qc/qc-milestones-gateways.md +[267e34f]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/267e34fc9f1fb9d76cc20032f3b09dc8e9dd82c7 diff --git a/docs/sqa/reviews/rc-012-source-code.md b/docs/sqa/reviews/rc-012-source-code.md new file mode 100644 index 0000000..fc013b7 --- /dev/null +++ b/docs/sqa/reviews/rc-012-source-code.md @@ -0,0 +1,52 @@ +# SQA Review Record: Source code of higher_lower + +## Metadata +| Key | Value | +| --- | --- | +| ID | RC-012 | +| CrossReference | [QC-PY-001] | + +## Version History +| Date | Status | Author | Reviewer | Change | Commit | +| --- | --- | --- | --- | --- | --- | +| 2026-10-04 | Accepted | Jens Tirsvad Nielsen | S01 | Initial version | [267e34f] | + +--- + +## Artifact Under Review + +- Instance reviewed: the Python source in `src/higher_lower/` and `tests/` at the commit of this review (source code has no artifact ID) +- Checklist used: [QC-PY-001] + +## Checklist Results + +| # | Criterion | Status | Evidence/Notes | +| --- | --- | --- | --- | +| 1 | Packages, modules, functions, variables, classes and constants follow PEP 8 casing (`snake_case`, `PascalCase`, `UPPER_SNAKE`) | Pass | Modules and functions snake_case, constants UPPER_SNAKE, TypedDict PascalCase; ruff (E, F, I, UP, FLY, B) passes. | +| 2 | Names state purpose in the domain's language; no unexplained abbreviations, no single-letter names outside tiny scopes | Pass | Names say purpose (check_answer, pick_pair); i/n-style names are not used. | +| 3 | Code is produced by the project's formatter and passes its linter with no unexplained suppressions | Pass | `ruff check` and `ruff format --check` pass; the only suppression is E501 for the verbatim data file, with a comment in pyproject.toml. | +| 4 | Every function and method signature is type-annotated, including `-> None` | Pass | All signatures annotated; `mypy --strict src tests` reports no issues. | +| 5 | No bare `except:`, no swallowed exceptions; specific exceptions are raised and the cause is kept (`raise ... from`) | Pass | No bare except; `main` catches EOFError and KeyboardInterrupt on purpose and leaves with a goodbye. | +| 6 | No mutable default arguments and no shadowed builtins | Pass | No mutable defaults; the data list default is a read-only module constant. | +| 7 | Files, locks and connections are managed with context managers | N-A | The code opens no files, locks or connections. | +| 8 | Public modules, classes and functions have docstrings that say what, not how (Optional) | Pass | Every module, class and function has a Doxygen docstring; checked with an AST script. | +| 9 | Logging uses `logging`, not `print`; no secrets or personal data in log output | N-A | The game prints its interface to the console; there is no logging, and no secrets or personal data are printed. | +| 10 | Classes and operations trace to the Design Class Diagram they implement; deviations are recorded | N-A | No Design Class Diagram exists or is planned; the only class is the Account TypedDict, and the functions implement the operations of SSD-001. | +| 11 | Tests exist for new behaviour, are named for the behaviour, and do not depend on order or the network | Pass | 36 pytest tests named for behaviour, with scripted input and seeded randomness; no network, no order dependence. | +| 12 | Type checker runs in strict mode without errors; `Any` is justified in a comment (Optional) | Pass | mypy strict runs without errors; no Any is used. | +| 13 | Dependencies are declared and pinned in the project's dependency file, none unused (Optional) | Pass | No runtime dependencies; dev tools declared in pyproject.toml with version ranges. | + +## Overall Verdict + +Go — all applicable criteria pass. The review found a lint ordering error, format differences and strict-typing errors; they were fixed before this verdict (ruff import order and format, `Final` on the account key constants). Reviewer and author are both S01: the project has a single participant, so the framework's author/reviewer separation cannot be met. S01 accepted this deviation when requesting acceptance (2026-10-04). + +## Action Items + +| Action | Owner | Due | +| --- | --- | --- | +| None | — | — | + +--- + +[QC-PY-001]: ../../../framework/qc/qc-programming-python.md +[267e34f]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/267e34fc9f1fb9d76cc20032f3b09dc8e9dd82c7 diff --git a/docs/sqa/traceability-matrix.md b/docs/sqa/traceability-matrix.md index fd2ea5e..ac0b1d9 100644 --- a/docs/sqa/traceability-matrix.md +++ b/docs/sqa/traceability-matrix.md @@ -9,8 +9,8 @@ ## Version History | Date | Status | Author | Reviewer | Change | Commit | | --- | --- | --- | --- | --- | --- | -| 2026-10-04 | Proposed | Jens Tirsvad Nielsen | S01 | Added RC-006 and the UC-001 artifacts | [923dde7] | | 2026-10-04 | Proposed | Jens Tirsvad Nielsen | S01 | Added RC-007 to RC-010 for UCD-001, US-001, UC-001 and SSD-001 | [c7164fe] | +| 2026-10-04 | Proposed | Jens Tirsvad Nielsen | S01 | Added RC-011 and RC-012 | [267e34f] | --- @@ -28,8 +28,8 @@ target is measurable. A row is added or updated whenever an artifact instance is | [PP-001] | PP | [BC-001], [SA-001] | [MIL-001], [MIL-002], [MIL-003], [MIL-004] | [RC-003] | | [MIL-001] | MIL | [BC-001], [PP-001] | - | [RC-004] | | [MIL-002] | MIL | [BC-001], [PP-001], [MIL-001] | - | [RC-005] | -| [MIL-003] | MIL | [BC-001], [PP-001], [MIL-002], [US-001] | [UC-001] | [RC-006] | -| [MIL-004] | MIL | [BC-001], [PP-001] | - | - | +| [MIL-003] | MIL | [BC-001], [PP-001], [MIL-002], [US-001] | [MIL-004], [UC-001] | [RC-006] | +| [MIL-004] | MIL | [BC-001], [PP-001], [MIL-003] | - | [RC-011] | | [UCD-001] | UCD | [SA-001], [BC-001] | [US-001], [UC-001] | [RC-007] | | [US-001] | US | [UCD-001], [BC-001], [MIL-003] | [UC-001] | [RC-008] | | [UC-001] | UC | [UCD-001], [US-001], [SA-001] | [SSD-001] | [RC-009] | @@ -38,6 +38,7 @@ target is measurable. A row is added or updated whenever an artifact instance is ## Coverage Notes - No domain model or design artifacts exist yet. +- RC-012 reviews the Python source against QC-PY-001; source code has no artifact ID, so it has no row above. - `-` in Upstream means foundational; in Downstream, nothing is built on it yet; in Last Reviewed, no `RC-*` exists yet. --- @@ -59,9 +60,11 @@ target is measurable. A row is added or updated whenever an artifact instance is [UC-001]: ../uc-001/uc.md [SSD-001]: ../uc-001/ssd.md [RC-006]: ./reviews/rc-006-mil-003.md -[923dde7]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/923dde7dc9b59d2c77eddc88336451193147c557 [RC-007]: ./reviews/rc-007-ucd-001.md [RC-008]: ./reviews/rc-008-us-001.md [RC-009]: ./reviews/rc-009-uc-001.md [RC-010]: ./reviews/rc-010-ssd-001.md [c7164fe]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/c7164feab1333951bf6f557baf95a26764656be0 +[RC-011]: ./reviews/rc-011-mil-004.md +[RC-012]: ./reviews/rc-012-source-code.md +[267e34f]: https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/014-higher_lower/commit/267e34fc9f1fb9d76cc20032f3b09dc8e9dd82c7 diff --git a/pyproject.toml b/pyproject.toml index 4b514db..60aefd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ license = { file = "LICENSE" } dependencies = [] [project.optional-dependencies] -dev = ["pytest>=8"] +dev = ["pytest>=9,<10", "ruff>=0.16,<0.17", "mypy>=2.4,<3"] [tool.setuptools.packages.find] where = ["src"] @@ -20,3 +20,16 @@ where = ["src"] [tool.pytest.ini_options] testpaths = ["tests"] pythonpath = ["src"] + +[tool.ruff] +line-length = 88 + +[tool.ruff.lint] +select = ["E", "F", "I", "UP", "FLY", "B"] + +[tool.ruff.lint.per-file-ignores] +"src/higher_lower/game_data.py" = ["E501"] # assignment data kept verbatim + +[tool.mypy] +strict = true +mypy_path = "src" diff --git a/src/higher_lower/art.py b/src/higher_lower/art.py index bd09c03..ed221f8 100644 --- a/src/higher_lower/art.py +++ b/src/higher_lower/art.py @@ -9,23 +9,37 @@ string, so Doxygen does not read the backticks in the art as markup. ## The game logo. logo = ( "\n" - r" __ ___ __ " "\n" - r" / / / (_)___ _/ /_ ___ _____" "\n" - r" / /_/ / / __ `/ __ \/ _ \/ ___/" "\n" - r" / __ / / /_/ / / / / __/ / " "\n" - r"/_/ ///_/\__, /_/ /_/\___/_/ " "\n" - r" / / /____/_ _____ _____" "\n" - r" / / / __ \ | /| / / _ \/ ___/" "\n" - r" / /___/ /_/ / |/ |/ / __/ / " "\n" - r"/_____/\____/|__/|__/\___/_/ " "\n" + r" __ ___ __ " + "\n" + r" / / / (_)___ _/ /_ ___ _____" + "\n" + r" / /_/ / / __ `/ __ \/ _ \/ ___/" + "\n" + r" / __ / / /_/ / / / / __/ / " + "\n" + r"/_/ ///_/\__, /_/ /_/\___/_/ " + "\n" + r" / / /____/_ _____ _____" + "\n" + r" / / / __ \ | /| / / _ \/ ___/" + "\n" + r" / /___/ /_/ / |/ |/ / __/ / " + "\n" + r"/_____/\____/|__/|__/\___/_/ " + "\n" ) ## The "vs" shown between the two accounts. vs = ( "\n" - r" _ __ " "\n" - r"| | / /____" "\n" - r"| | / / ___/" "\n" - r"| |/ (__ ) " "\n" - r"|___/____(_)" "\n" + r" _ __ " + "\n" + r"| | / /____" + "\n" + r"| | / / ___/" + "\n" + r"| |/ (__ ) " + "\n" + r"|___/____(_)" + "\n" ) diff --git a/src/higher_lower/constants.py b/src/higher_lower/constants.py index 90574fc..cfd1993 100644 --- a/src/higher_lower/constants.py +++ b/src/higher_lower/constants.py @@ -2,11 +2,13 @@ @brief Constants shared by the game modules. """ +from typing import Final + ## Keys of an account dictionary. -KEY_NAME = "name" -KEY_FOLLOWER_COUNT = "follower_count" -KEY_DESCRIPTION = "description" -KEY_COUNTRY = "country" +KEY_NAME: Final = "name" +KEY_FOLLOWER_COUNT: Final = "follower_count" +KEY_DESCRIPTION: Final = "description" +KEY_COUNTRY: Final = "country" ## The two choices the player can type, in lower case. CHOICE_A = "a" diff --git a/src/higher_lower/game_logic.py b/src/higher_lower/game_logic.py index c28223d..a8c5260 100644 --- a/src/higher_lower/game_logic.py +++ b/src/higher_lower/game_logic.py @@ -1,5 +1,5 @@ """@file game_logic.py -@brief Pure functions of the game: drawing accounts, describing them and checking guesses. +@brief Pure game functions: draw accounts, describe them, check guesses. """ import random @@ -9,9 +9,9 @@ from higher_lower.constants import ( ACCOUNT_TEMPLATE, CHOICE_A, CHOICE_B, + KEY_COUNTRY, KEY_DESCRIPTION, KEY_NAME, - KEY_COUNTRY, ) from higher_lower.game_data import Account, data diff --git a/tests/test_game.py b/tests/test_game.py index 427f9d1..285a3aa 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -14,20 +14,37 @@ from higher_lower.game import ask_choice, play_game, show_round from higher_lower.game_data import Account ACCOUNTS: list[Account] = [ - {"name": "First", "follower_count": 30, "description": "Test one", "country": "Denmark"}, - {"name": "Second", "follower_count": 20, "description": "Test two", "country": "Norway"}, - {"name": "Third", "follower_count": 10, "description": "Test three", "country": "Sweden"}, + { + "name": "First", + "follower_count": 30, + "description": "Test one", + "country": "Denmark", + }, + { + "name": "Second", + "follower_count": 20, + "description": "Test two", + "country": "Norway", + }, + { + "name": "Third", + "follower_count": 10, + "description": "Test three", + "country": "Sweden", + }, ] class FirstRng(random.Random): - """@brief Random generator that always takes the first entries, so a game is fixed.""" + """@brief Random generator that takes the first entries, so a game is fixed.""" - def sample(self, population: Sequence, k: int, **kwargs: object) -> list: # type: ignore[override] + def sample( # type: ignore[override] + self, population: Sequence[Account], k: int, **kwargs: object + ) -> list[Account]: """@brief Return the first k entries.""" return list(population)[:k] - def choice(self, seq: Sequence) -> Account: # type: ignore[override] + def choice(self, seq: Sequence[Account]) -> Account: # type: ignore[override] """@brief Return the first entry.""" return seq[0] diff --git a/tests/test_game_logic.py b/tests/test_game_logic.py index b153b65..5c6b0fb 100644 --- a/tests/test_game_logic.py +++ b/tests/test_game_logic.py @@ -58,8 +58,7 @@ def test_format_data_describes_the_account() -> None: "country": "United States", } assert ( - format_data(account) - == "Nike, a Sportswear multinational, from United States" + format_data(account) == "Nike, a Sportswear multinational, from United States" )