Skip to content

refactor: modularize architecture with test coverage - #1

Open
ShadowoftheRavens wants to merge 2 commits into
gdr-sys:mainfrom
ShadowoftheRavens:main
Open

ShadowoftheRavens wants to merge 2 commits into
gdr-sys:mainfrom
ShadowoftheRavens:main

Conversation

@ShadowoftheRavens

Copy link
Copy Markdown

Description

This PR refactors the 7th Sea Dice Roller application from a monolithic structure into a modular, layered architecture with comprehensive test coverage.

Changes

Architecture Refactoring

  • Modularization: Split app.mjs into 5 focused modules:

    • controller.mjs - Event binding and action dispatch
    • renderer.mjs - DOM rendering and markup generation
    • app-state.mjs - State shape and mutations
    • dice-service.mjs - Dice rolling and explosion mechanics
    • app-logic.mjs - Partition search algorithm and game logic
  • Styling: Extracted all CSS into styles.css for separation of concerns

  • Constants: Created constants.mjs with centralized:

    • Scoring weights (increment: 1M, leftover: 1K)
    • Game configuration (targets 10/15, natural explosion 10)
    • UI labels (Italian localization)
    • CSS class names and DOM element IDs

Algorithm Improvements

  • Partition Search: Replaced recursive algorithm with iterative DFS stack-based approach
    • Improved maintainability and reasoning
    • Better memory efficiency
    • Easier to test and debug

Test Coverage

  • Added 20 comprehensive regression tests covering:
    • Edge cases (empty dice, below-threshold, single die)
    • Core behavior (10-point and 15-point set formation)
    • Scoring policy (increment prioritization validation)
    • Algorithm consistency (deterministic results)

Validation

  • All 20 regression tests pass (143.7ms)
  • No syntax errors in any module
  • 100% backward compatibility maintained
  • Existing game behavior unchanged

How to Test

Run the regression test suite:

node --test tests/regression.test.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant