-
Notifications
You must be signed in to change notification settings - Fork 0
feat(paint-calculator): add round room support with shape selection menu #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9891a8
feat(paint-calculator): add sealed RoomDimensions interface with Rect…
durimkryeziu 832d814
refactor(paint-calculator): extract RectangularRoom and RoundRoom to …
durimkryeziu 747659a
refactor(paint-calculator): PaintEstimator works with sealed RoomDime…
durimkryeziu d963e53
feat(paint-calculator): add shape selection menu for rectangular and …
durimkryeziu d906c2c
test(paint-calculator): add nested JUnit tests for RoundRoom
durimkryeziu 370dfb0
fix(paint-calculator): address checkstyle violations and update tests…
durimkryeziu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
paint-calculator/src/main/java/dev/delivercraft/paint/RectangularRoom.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package dev.delivercraft.paint; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
|
|
||
| public record RectangularRoom(RoomDimension length, RoomDimension width) implements RoomDimensions { | ||
|
|
||
| public RectangularRoom(RoomDimension length, RoomDimension width) { | ||
| this.length = Objects.requireNonNull(length, "length must not be null"); | ||
| this.width = Objects.requireNonNull(width, "width must not be null"); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal area() { | ||
| return this.length.value().multiply(this.width.value()); | ||
| } | ||
| } |
12 changes: 2 additions & 10 deletions
12
paint-calculator/src/main/java/dev/delivercraft/paint/RoomDimensions.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,8 @@ | ||
| package dev.delivercraft.paint; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
|
|
||
| record RoomDimensions(RoomDimension length, RoomDimension width) { | ||
| sealed interface RoomDimensions permits RectangularRoom, RoundRoom { | ||
|
|
||
| RoomDimensions { | ||
| Objects.requireNonNull(length, "length must not be null"); | ||
| Objects.requireNonNull(width, "width must not be null"); | ||
| } | ||
|
|
||
| BigDecimal area() { | ||
| return this.length.value().multiply(this.width.value()); | ||
| } | ||
| BigDecimal area(); | ||
| } |
18 changes: 18 additions & 0 deletions
18
paint-calculator/src/main/java/dev/delivercraft/paint/RoundRoom.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package dev.delivercraft.paint; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.Objects; | ||
|
|
||
| public record RoundRoom(RoomDimension radius) implements RoomDimensions { | ||
|
|
||
| public RoundRoom(RoomDimension radius) { | ||
| this.radius = Objects.requireNonNull(radius, "radius must not be null"); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal area() { | ||
| return this.radius.value() | ||
| .multiply(this.radius.value()) | ||
| .multiply(BigDecimal.valueOf(Math.PI)); | ||
| } | ||
| } |
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
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
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
91 changes: 91 additions & 0 deletions
91
paint-calculator/src/test/java/dev/delivercraft/paint/RoundRoomTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package dev.delivercraft.paint; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.BigInteger; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| class RoundRoomTest { | ||
|
|
||
| @Nested | ||
| class AreaCalculation { | ||
|
|
||
| @Test | ||
| void area_GivenRadius10_ShouldBePiTimesRadiusSquared() { | ||
| RoundRoom room = new RoundRoom(RoomDimension.of("10")); | ||
|
|
||
| BigDecimal area = room.area(); | ||
|
|
||
| BigDecimal expected = BigDecimal.valueOf(Math.PI) | ||
| .multiply(BigDecimal.valueOf(100)); | ||
| assertThat(area).isEqualByComparingTo(expected.stripTrailingZeros()); | ||
| } | ||
|
|
||
| @Test | ||
| void area_GivenRadius1_ShouldBePi() { | ||
| RoundRoom room = new RoundRoom(RoomDimension.of("1")); | ||
|
|
||
| BigDecimal area = room.area(); | ||
|
|
||
| assertThat(area).isEqualByComparingTo(BigDecimal.valueOf(Math.PI)); | ||
| } | ||
|
|
||
| @Test | ||
| void area_GivenDecimalRadius_ShouldCalculateCorrectly() { | ||
| RoundRoom room = new RoundRoom(RoomDimension.of("5.5")); | ||
|
|
||
| BigDecimal area = room.area(); | ||
|
|
||
| BigDecimal expected = BigDecimal.valueOf(Math.PI) | ||
| .multiply(BigDecimal.valueOf(5.5)) | ||
| .multiply(BigDecimal.valueOf(5.5)); | ||
| assertThat(area).isEqualByComparingTo(expected.stripTrailingZeros()); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class Validation { | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = {"0", "0.0", "-1", "-5"}) | ||
| void construction_GivenZeroOrNegativeRadius_ShouldThrow(String input) { | ||
| assertThatIllegalArgumentException() | ||
| .isThrownBy(() -> new RoundRoom(RoomDimension.of(input))); | ||
| } | ||
|
|
||
| @Test | ||
| void construction_GivenNullRadius_ShouldThrowNullPointerException() { | ||
| assertThatThrownBy(() -> new RoundRoom(null)) | ||
| .isInstanceOf(NullPointerException.class); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class PaintEstimation { | ||
|
|
||
| @Test | ||
| void estimate_GivenRoundRoomRadius10_ShouldCalculateOneGallon() { | ||
| RoomDimensions room = new RoundRoom(RoomDimension.of("10")); | ||
|
|
||
| PaintEstimate estimate = PaintEstimator.estimate(room); | ||
|
|
||
| assertThat(estimate.gallons()).isEqualByComparingTo(BigInteger.ONE); | ||
| assertThat(estimate.area()).isEqualTo("314.1592653589793"); | ||
| } | ||
|
|
||
| @Test | ||
| void estimate_GivenRoundRoomRadius15_ShouldCalculateThreeGallons() { | ||
| RoomDimensions room = new RoundRoom(RoomDimension.of("15")); | ||
|
|
||
| PaintEstimate estimate = PaintEstimator.estimate(room); | ||
|
|
||
| assertThat(estimate.gallons()).isEqualByComparingTo(BigInteger.valueOf(3)); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test coverage for invalid shape selection.
The new shape-selection logic correctly throws
IllegalArgumentExceptionfor 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
🤖 Prompt for AI Agents