-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
426fa9c
commit 7a12c7a
Showing
7 changed files
with
80 additions
and
91 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
java/pizza-party/src/main/java/org/example/domain/Piece.java
This file contains 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,29 @@ | ||
package org.example.domain; | ||
|
||
import java.util.Objects; | ||
|
||
public class Piece { | ||
private int pieces; | ||
public Piece(final int pieces) { | ||
if(pieces <= 0) { | ||
throw new IllegalArgumentException("피자 조각 개수는 0개 이상이여야 합니다."); | ||
} | ||
if(pieces % 2 != 0) { | ||
throw new IllegalArgumentException("피자 조각 개수는 짝수여야 합니다."); | ||
} | ||
this.pieces = pieces; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Piece pizza = (Piece) o; | ||
return pieces == pizza.pieces; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(pieces); | ||
} | ||
} |
28 changes: 16 additions & 12 deletions
28
java/pizza-party/src/main/java/org/example/domain/Pizza.java
This file contains 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,29 +1,33 @@ | ||
package org.example.domain; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.IntStream; | ||
|
||
public class Pizza { | ||
private int pieces; | ||
public Pizza(int pieces) { | ||
if(pieces <= 0) { | ||
throw new IllegalArgumentException("피자 조각 개수는 양수여야 합니다."); | ||
} | ||
if(pieces % 2 != 0) { | ||
throw new IllegalArgumentException("피자 조각 개수는 짝수여야 합니다."); | ||
} | ||
this.pieces = pieces; | ||
private final List<Piece> pieces; | ||
|
||
private Pizza(final List<Piece> pizzas) { | ||
this.pieces = pizzas; | ||
} | ||
|
||
public static Pizza init(final int piece, final int pizzaCount) { | ||
final List<Piece> pizzas = IntStream.range(0, pizzaCount) | ||
.mapToObj(pizza -> new Piece(piece)) | ||
.toList(); | ||
return new Pizza(pizzas); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Pizza pizza = (Pizza) o; | ||
return pieces == pizza.pieces; | ||
Pizza pizzas1 = (Pizza) o; | ||
return Objects.equals(pieces, pizzas1.pieces); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
public int hashCode() { | ||
return Objects.hash(pieces); | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
java/pizza-party/src/main/java/org/example/domain/Pizzas.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,29 @@ | ||
package domain; | ||
|
||
import org.example.domain.Piece; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
public class PieceTests { | ||
|
||
@ParameterizedTest | ||
@DisplayName("피자 조각 개수가 0 이하일 경우 예외발생") | ||
@ValueSource(ints = {-1, 0}) | ||
void 피자_조각_개수가_0이하일_경우_예외_발생(int invalidPieceCount) { | ||
assertThatThrownBy(() -> new Piece(invalidPieceCount)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("피자 조각 개수는 1개 이상이어야 합니다."); | ||
} | ||
|
||
@ParameterizedTest | ||
@DisplayName("피자 조각 개수가 홀수일 경우 예외발생") | ||
@ValueSource(ints = {1, 9}) | ||
void 피자_조각_개수가_홀수일_경우_예외_발생(int oddPieceCount) { | ||
assertThatThrownBy(() -> new Piece(oddPieceCount)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("피자 조각 개수는 짝수여야 합니다."); | ||
} | ||
} |
This file contains 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,28 +1,13 @@ | ||
package domain; | ||
|
||
import org.example.domain.Piece; | ||
import org.example.domain.Pizza; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import java.util.List; | ||
|
||
public class PizzaTests { | ||
@ParameterizedTest | ||
@ValueSource(ints = {-1, 0}) | ||
@DisplayName("피자 조각 개수는 양수여야 합니다..") | ||
void test(int pieces) { | ||
assertThatThrownBy(() -> new Pizza(pieces)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("피자 조각 개수는 양수여야 합니다."); | ||
} | ||
@ParameterizedTest | ||
@ValueSource(ints = {1, 5, 7}) | ||
@DisplayName("피자 조각 개수는 짝수이어야 합니다.") | ||
void test1(int pieces) { | ||
assertThatThrownBy(() -> new Pizza(pieces)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("피자 조각 개수는 짝수여야 합니다."); | ||
} | ||
} | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class PizzaTests { | ||
} |
This file was deleted.
Oops, something went wrong.