Refactor: Modularize Gilded Rose Python Implementation#1
Open
krs-github16 wants to merge 12 commits intomainfrom
Open
Refactor: Modularize Gilded Rose Python Implementation#1krs-github16 wants to merge 12 commits intomainfrom
krs-github16 wants to merge 12 commits intomainfrom
Conversation
…uage for setting up TextTest
…gic, and update tests - Add min/max_quality, exceptional_items, and improving_items - Simplify update_quality with capped increments for backstage passes - Add ApprovalTests config and quiet fallback reporter for approvals tests - Normalize test item names to 'Normal Item'
… added unit tests
- Add legendary_items (previously exceptional), conjured_items (new change request) and quality bounds - Simplify update_quality() logic and backstage increments test(gilded_rose): expand tests and update approvals - Add factory setUp, item creation tests and conjured tests - Update approvals golden file for new fixture items
… with predicate and helper fucntions. Add MIN/MAX quality constants and backstage thresholds for clarity. Factor item-type predicates and small helper methods (aged brie, backstage, conjured, legendary). Implement legendary behavior (Sulfuras fixed at quality 80) and conjured extra degradation (degrades twice as fast). Normalize/cap quality at entry and after updates to prevent out-of-range values. Replace long if-chains with clearer increment/decrement helpers and targeted checks. Add docstrings
… bounds, add conjured & legendary handling Factor update logic into per-item helpers and add explicit normalization and conjured/legendary handling. - Add MIN/MAX quality and normalize_quality() to bound item quality. - Split update logic into _update_* helpers for normal/Aged Brie/backstage/conjured. - Normalize Sulfuras to fixed LEGENDARY_QUALITY (80). - Centralize sell_in decrement for non-legendary items. See tests for edge cases (conjured semantics and normalization).
…tem update logic - Add GildedRoseUpdater with quality bounds, Sulfuras handling (quality=80), and backstage thresholds - Move update logic for normal, Aged Brie, Backstage, and Conjured items into updater - Normalize quality and update sell_in consistently in one place
…r; rename update_quality -> update and update usages in tests and debug scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces a full, incremental refactor of the Gilded Rose Python implementation. The goal is to improve clarity, maintainability, extensibility, and correctness while preserving the original business rules through comprehensive testing.
Across a series of 12 commits, the legacy monolithic implementation has been progressively transformed into a modular, test-driven design.
Key Improvements
1. Introduced Comprehensive Tests
Added unit tests to preserve original behaviour and prevent regressions.
Added ApprovalTests for end-to-end behavioural validation.
Normalized fixture item names and expanded coverage
2. Reduced Deeply Nested Conditionals
Simplified initial logic by reducing nested if/else blocks to improve readability.
Clarified quality-change rules through small, targeted helper functions.
3. Added Item-Specific Update Helpers
Refactored update logic into explicit per-item functions:
_update_normal_item_quality
_update_aged_brie_quality
_update_backstage_pass_item_quality
_update_conjured_item_quality
Unified sell_in updates under _update_sell_in.
This eliminated duplication and clarified the behavioural differences across item types.
4. Centralized Quality Rules
Introduced:
MIN_QUALITY
MAX_QUALITY
LEGENDARY_QUALITY
Backstage threshold constants
Added centralized _normalize_quality to enforce bounds after every update.
5. Introduced a Dedicated Updater
Extracted a new class GildedRoseUpdater to encapsulate all update logic.
GildedRose now delegates updates to this updater, improving separation of concerns.
Future item types can be added cleanly by extending the updater.
6. Modularized the Codebase
Codebase reorganised into dedicated modules:
item.py — Item model
product_list.py — Enum for product identifiers
gilded_rose_updater.py — All item-specific update logic
gilded_rose.py — Orchestration and high-level update flow
debug_gilded_rose.py — Debug driver for manual inspection
Updated test suite structure under python/tests
This separation significantly improves readability and long-term maintainability.
Behaviour Preservation
All changes are validated by:
Legendary items retain fixed quality (80)
Conjured items degrade at twice the normal rate
Backstage passes follow correct increasing behaviour and drop to zero after event
Why This Refactor Matters