Skip to content

feat(paint-calculator): add round room support with shape selection menu#22

Closed
durimkryeziu wants to merge 6 commits into
mainfrom
round-room-support
Closed

feat(paint-calculator): add round room support with shape selection menu#22
durimkryeziu wants to merge 6 commits into
mainfrom
round-room-support

Conversation

@durimkryeziu
Copy link
Copy Markdown
Owner

@durimkryeziu durimkryeziu commented May 24, 2026

Summary

  • Add sealed RoomDimensions interface with RectangularRoom and RoundRoom implementing records
  • Add shape selection menu to PaintCalculator (1=Rectangular, 2=Round)
  • Update PaintEstimator to work polymorphically with sealed interface
  • Add comprehensive RoundRoomTest with nested JUnit test classes

Test Plan

  • All 55 paint-calculator tests pass
  • Checkstyle passes (no violations)
  • PMD passes (no violations)

Changes

  • RoomDimensions.java — sealed interface with permits clause
  • RectangularRoom.java — extracted record implementing sealed interface
  • RoundRoom.java — new circular room record (πr² area calculation)
  • PaintCalculator.java — menu-driven shape selection with switch expression
  • PaintCalculatorTest.java — updated for menu flow, added round room test
  • RoundRoomTest.java — new test class with area, validation, and paint estimation nested tests
  • MainTest.java — updated input to include shape selection

Summary by CodeRabbit

Release Notes

  • New Features
    • Added shape selection menu enabling users to choose between rectangular and round room types
    • Introduced radius-based input for circular room paint calculations, expanding beyond rectangular-only support
    • Paint calculator now generates accurate paint estimates for both rectangular and round room configurations

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

📝 Walkthrough

Walkthrough

The PR extends the paint calculator to support round rooms in addition to rectangular rooms by introducing a sealed interface-based type hierarchy and refactoring the user input flow to let users select room shape before entering dimensions.

Changes

Room dimension type abstraction

Layer / File(s) Summary
Room dimension types and implementations
paint-calculator/src/main/java/dev/delivercraft/paint/RoomDimensions.java, paint-calculator/src/main/java/dev/delivercraft/paint/RectangularRoom.java, paint-calculator/src/main/java/dev/delivercraft/paint/RoundRoom.java
RoomDimensions is refactored to a sealed interface declaring an abstract area() method. RectangularRoom implements it with length and width fields, multiplying their BigDecimal values for area. RoundRoom implements it with a radius field, computing area as radius² × π. Both enforce non-null fields.
Type integration and behavior tests
paint-calculator/src/test/java/dev/delivercraft/paint/PaintEstimatorTest.java, paint-calculator/src/test/java/dev/delivercraft/paint/RoundRoomTest.java
PaintEstimatorTest is wired to use the new RectangularRoom constructor. A comprehensive new test suite RoundRoomTest verifies RoundRoom area calculations, non-null validation, and paint estimation across integer and decimal radii.

Calculator shape-selection refactoring

Layer / File(s) Summary
Calculator shape-selection logic
paint-calculator/src/main/java/dev/delivercraft/paint/PaintCalculator.java
New string constants define the shape menu and dimension prompts. calculatePaint() displays the menu, reads the user's shape choice (1 for rectangular, 2 for round), dispatches to readRectangularDimensions() or readRoundDimensions() to build the appropriate room object, and outputs the paint estimate. Invalid choices raise IllegalArgumentException.
Calculator behavior tests
paint-calculator/src/test/java/dev/delivercraft/paint/MainTest.java, paint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.java
All calculator tests are updated to supply shape selection (option 1 or 2) as the first input line. Tests assert full output including shape menu, dimension prompts, and computed gallons. A new test verifies round-room selection. Invalid-input tests confirm error messages include the menu and prompts.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Calculator
  participant Estimator
  User->>Calculator: Provide shape (1 or 2) + dimensions
  Calculator->>Calculator: Display shape menu
  Calculator->>Calculator: Parse user shape choice
  alt shape == 1
    Calculator->>Calculator: readRectangularDimensions()
  else shape == 2
    Calculator->>Calculator: readRoundDimensions()
  end
  Calculator->>Estimator: Invoke with RoomDimensions
  Estimator->>Calculator: Return PaintEstimate
  Calculator->>User: Print purchase message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit hops through type abstraction's door,
From rectangles alone to round rooms more.
With sealed interface holding fast the way,
Shape selection blooms for user's play. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: introducing round room support with a shape selection menu, which is the primary feature delivered across the refactored RoomDimensions interface, new RoundRoom implementation, and updated PaintCalculator.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch round-room-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.85%. Comparing base (2a8a182) to head (370dfb0).

Files with missing lines Patch % Lines
...n/java/dev/delivercraft/paint/PaintCalculator.java 87.50% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #22      +/-   ##
============================================
+ Coverage     77.41%   77.85%   +0.43%     
- Complexity      116      120       +4     
============================================
  Files            33       34       +1     
  Lines           403      420      +17     
  Branches         24       25       +1     
============================================
+ Hits            312      327      +15     
- Misses           84       85       +1     
- Partials          7        8       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@paint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.java`:
- Around line 152-162: Add unit tests that assert PaintCalculator.calculatePaint
throws IllegalArgumentException for invalid shape input: create tests using
StubLineReader and CapturingLineWriter to pass values like "3","0","abc","", " 
" (use a `@ParameterizedTest` with `@ValueSource`) and a separate test for a null
input, then
assertThatIllegalArgumentException().isThrownBy(calculator::calculatePaint).withMessage("Please
enter 1 or 2"); also assert the CapturingLineWriter contains only SHAPE_MENU +
System.lineSeparator() before the exception is thrown to verify prompt output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0c9e3205-4819-4d22-8536-9d505964ee7d

📥 Commits

Reviewing files that changed from the base of the PR and between 2a8a182 and 370dfb0.

📒 Files selected for processing (8)
  • paint-calculator/src/main/java/dev/delivercraft/paint/PaintCalculator.java
  • paint-calculator/src/main/java/dev/delivercraft/paint/RectangularRoom.java
  • paint-calculator/src/main/java/dev/delivercraft/paint/RoomDimensions.java
  • paint-calculator/src/main/java/dev/delivercraft/paint/RoundRoom.java
  • paint-calculator/src/test/java/dev/delivercraft/paint/MainTest.java
  • paint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.java
  • paint-calculator/src/test/java/dev/delivercraft/paint/PaintEstimatorTest.java
  • paint-calculator/src/test/java/dev/delivercraft/paint/RoundRoomTest.java

Comment on lines +152 to +162
@Test
void calculatePaint_GivenRoundRoomSelection_ShouldCalculateCorrectArea() {
LineWriter lineWriter = new CapturingLineWriter();
PaintCalculator calculator = new PaintCalculator(new StubLineReader("2", "10"), lineWriter);

calculator.calculatePaint();

String output = lineWriter.toString();
assertThat(output).startsWith(SHAPE_MENU + System.lineSeparator() + RADIUS_PROMPT);
assertThat(output).contains("You will need to purchase 1 gallon of paint to cover");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add test coverage for invalid shape selection.

The new shape-selection logic correctly throws IllegalArgumentException for invalid input, but there's no explicit test verifying this behavior. Consider adding a test case to document expected behavior and prevent regressions.

🧪 Suggested test case
`@ParameterizedTest`
`@ValueSource`(strings = {"3", "0", "abc", "", "  "})
void calculatePaint_GivenInvalidShapeSelection_ShouldThrowException(String invalidShape) {
    LineWriter lineWriter = new CapturingLineWriter();
    PaintCalculator calculator = new PaintCalculator(
            new StubLineReader(invalidShape), lineWriter);

    assertThatIllegalArgumentException()
            .isThrownBy(calculator::calculatePaint)
            .withMessage("Please enter 1 or 2");
    
    assertThat(lineWriter).hasToString(SHAPE_MENU + System.lineSeparator());
}

`@Test`
void calculatePaint_GivenNullShapeSelection_ShouldThrowException() {
    LineWriter lineWriter = new CapturingLineWriter();
    PaintCalculator calculator = new PaintCalculator(
            new StubLineReader((String) null), lineWriter);

    assertThatIllegalArgumentException()
            .isThrownBy(calculator::calculatePaint)
            .withMessage("Please enter 1 or 2");
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@paint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.java`
around lines 152 - 162, Add unit tests that assert
PaintCalculator.calculatePaint throws IllegalArgumentException for invalid shape
input: create tests using StubLineReader and CapturingLineWriter to pass values
like "3","0","abc","", "  " (use a `@ParameterizedTest` with `@ValueSource`) and a
separate test for a null input, then
assertThatIllegalArgumentException().isThrownBy(calculator::calculatePaint).withMessage("Please
enter 1 or 2"); also assert the CapturingLineWriter contains only SHAPE_MENU +
System.lineSeparator() before the exception is thrown to verify prompt output.

@durimkryeziu durimkryeziu deleted the round-room-support branch May 24, 2026 02:00
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.

2 participants