-
Notifications
You must be signed in to change notification settings - Fork 13
[BE] μ΄κ·Όν πμ λ€μ΄ #9
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
base: rootTiket
Are you sure you want to change the base?
Changes from all commits
dbf4654
aaee927
4e607b0
d9f9292
17e5e8b
161c13b
3f5ec64
8c2c292
16c549f
e82ec03
846e9dd
cc14d31
5d7626a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package leets.land; | ||
|
|
||
| import leets.land.domain.Range; | ||
| import leets.land.domain.CharRange; | ||
| import leets.land.view.InputView; | ||
| import leets.land.view.OutputView; | ||
|
|
||
| public class Controller { | ||
| private final InputView inputView = new InputView(); | ||
| private final OutputView outputView = new OutputView(); | ||
| public void run() { | ||
| int version = inputView.getVersionInput(); | ||
| if (version == 1) { | ||
| numberVersion(); | ||
| } else { | ||
| alphaVersion(); | ||
| } | ||
| } | ||
| public void numberVersion() { | ||
| double randomValue = Math.random(); | ||
| int randomNumber = (int)(randomValue *100) +1; | ||
| int cnt = 0; | ||
| int correct = -1; | ||
| Range range = new Range(1, 100); | ||
| while (correct != randomNumber) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ λ΅κ³Ό λΉκ΅νλ κ² Controllerμ μν μΈκ°μ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. contoller μμ λΆλ¦¬νλ €κ³ νλλ° μλ‘μ΄ ν΄λμ€λ₯Ό λ§λ€μ΄μ λ°λ‘ κ²μ¦νλ κ²μ΄ λ μ’μ λ°©ν₯μΌκΉμ? |
||
| correct = inputView.getNumberInput(range); | ||
| printUpDown(correct, randomNumber, range); // Call printUpDown function | ||
| cnt ++; | ||
| } | ||
| outputView.printCorrectMessage(cnt); | ||
| } | ||
|
|
||
| public void printUpDown(int correct, int randomNumber, Range range) { | ||
| if (correct < randomNumber) { | ||
| System.out.println("UP"); | ||
| range.setMin(correct + 1); | ||
| } else if (correct > randomNumber) { | ||
| System.out.println("DOWN"); | ||
| range.setMax(correct - 1); | ||
| } | ||
| } | ||
|
|
||
| public void alphaVersion() { | ||
| char randomAlpha = (char)((Math.random() * 58) + 65); | ||
| int cnt = 0; | ||
| char correct = 'A'-1; | ||
| CharRange range = new CharRange('A', 'z'); | ||
| while (correct != randomAlpha) { | ||
| correct = inputView.getCharInput(range); | ||
| printUpDown(correct, randomAlpha, range); | ||
| cnt ++; | ||
| } | ||
| outputView.printCorrectMessage(cnt); | ||
| } | ||
|
|
||
| public void printUpDown(char correct, char randomAlpha, CharRange range) { | ||
| if (correct < randomAlpha) { | ||
| System.out.println("UP"); | ||
| range.setMin((char)(correct + 1)); | ||
| } else if (correct > randomAlpha) { | ||
| System.out.println("DOWN"); | ||
| range.setMax((char)(correct - 1)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a->Zκ° λλ κ²½μ°λ μμ€ν€ μ½λλ₯Ό μκ°ν΄μ ν΄μ£Όμ μΌλ κ±°κ°μμ |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| package leets.land; | ||
|
|
||
| public class UpdownApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.print("hihi :D"); | ||
| Controller controller = new Controller(); | ||
| controller.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package leets.land.domain; | ||
|
|
||
| public class CharRange { | ||
| private char min; | ||
| private char max; | ||
|
|
||
| public CharRange(char min, char max) { | ||
| this.min = min; | ||
| this.max = max; | ||
| } | ||
|
|
||
| public char getMin() { | ||
| return min; | ||
| } | ||
|
|
||
| public char getMax() { | ||
| return max; | ||
| } | ||
|
|
||
| public void setMin(char min) { | ||
| this.min = min; | ||
| } | ||
|
|
||
| public void setMax(char max) { | ||
| this.max = max; | ||
| } | ||
|
Comment on lines
+20
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ°μ²΄κ° μΌνκ² νλ κ²μ΄ μ΄λ¨κΉμ? |
||
|
|
||
| public boolean isInRange(char value) { | ||
| return value >= min && value <= max; | ||
| } | ||
|
Comment on lines
+28
to
+30
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ°μ²΄κ° μΌνκ³ μλ€μ ! μ’μμπ |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package leets.land.domain; | ||
|
|
||
| public class Range { | ||
| private int min; | ||
| private int max; | ||
|
|
||
| public Range(int min, int max) { | ||
| this.min = min; | ||
| this.max = max; | ||
| } | ||
|
|
||
| public int getMin() { | ||
| return min; | ||
| } | ||
|
|
||
| public void setMin(int min) { | ||
| this.min = min; | ||
| } | ||
|
|
||
| public int getMax() { | ||
| return max; | ||
| } | ||
|
|
||
| public void setMax(int max) { | ||
| this.max = max; | ||
| } | ||
|
|
||
| public boolean isInRange(int value) { | ||
| return value >= min && value <= max; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package leets.land.view; | ||
|
|
||
| import leets.land.domain.CharRange; | ||
| import leets.land.domain.Range; | ||
|
|
||
| import java.util.InputMismatchException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class InputView { | ||
| private final Scanner scanner = new Scanner(System.in); | ||
|
|
||
| public int getVersionInput() { | ||
| System.out.print("λ²μ μ μ λ ₯ν΄μ£ΌμΈμ (μ«μ λ²μ : 1, μμ΄ λ²μ : 2) : "); | ||
| try { | ||
| int version = scanner.nextInt(); | ||
| validateVersion(version); | ||
| return version; | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return getVersionInput(); | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("[ERROR] λ²μ μ μ λ ₯ν΄μ£ΌμΈμ (μ«μ λ²μ : 1, μμ΄ λ²μ : 2) : "); | ||
| scanner.nextLine(); | ||
| return getVersionInput(); | ||
| } | ||
| } | ||
|
|
||
| public void validateVersion(int version) { | ||
| if (version != 1 && version != 2) { | ||
| throw new IllegalArgumentException("[ERROR] μ‘΄μ¬νμ§ μλ λ²μ μ λλ€."); | ||
| } | ||
| } | ||
|
|
||
| public int getNumberInput(Range range) { | ||
| System.out.printf("μ«μλ₯Ό μ λ ₯ν΄μ£ΌμΈμ(%d ~ %d) : ",range.getMin(),range.getMax()); | ||
| try { | ||
| int number = scanner.nextInt(); | ||
| validateNumberRange(range, number); | ||
| return number; | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return getNumberInput(range); | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("[ERROR] μ«μλ₯Ό μ λ ₯ν΄μ£ΌμΈμ "); | ||
| scanner.nextLine(); | ||
| return getNumberInput(range); | ||
| } | ||
| } | ||
|
|
||
| public void validateNumberRange(Range range, int number) { | ||
| if (!range.isInRange(number)) { | ||
| throw new IllegalArgumentException("[ERROR] λ²μ λ΄μ μ«μλ₯Ό μ λ ₯νμΈμ. "); | ||
| } | ||
| } | ||
|
|
||
| public char getCharInput(CharRange range) { | ||
| System.out.printf("μμ΄λ₯Ό μ λ ₯ν΄μ£ΌμΈμ(%c ~ %c) : ",range.getMin(),range.getMax()); | ||
| String input = scanner.next(); | ||
| try { | ||
| validCharLength(input); | ||
| char character = input.charAt(0); | ||
| validateCharRange(range, character); | ||
| return character; | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return getCharInput(range); | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("μ λ ₯ λ¬Έμμ νμ μ΄ λ§μ§ μμ΅λλ€. "); | ||
| scanner.nextLine(); | ||
| return getCharInput(range); | ||
| } | ||
| } | ||
| public void validateCharRange(CharRange range, char character) { | ||
| if (!range.isInRange(character)) { | ||
| throw new IllegalArgumentException("[ERROR] λ²μ λ΄μ μνλ²³μ μ λ ₯νμΈμ. "); | ||
| } | ||
| } | ||
| public void validCharLength(String s) { | ||
| if (s.length() >= 2) { | ||
| throw new IllegalArgumentException("[ERROR] μνλ²³ ν κΈμλ§ μ λ ₯ν΄μ£ΌμΈμ "); | ||
| } | ||
| } | ||
|
Comment on lines
+78
to
+82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μνλ²³μ μ¬λ¬κ°λ₯Ό μ λ ₯νλ μμΈμ²λ¦¬λ μκ°λͺ»νλλ° μ’μκ±° κ°μ΅λλ€! |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package leets.land.view; | ||
|
|
||
| public class OutputView { | ||
| public void printCorrectMessage(int cnt) { | ||
| System.out.println("μ λ΅"); | ||
|
|
||
| System.out.printf("μλν νμ : %dν",cnt); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,21 @@ | ||
| package leets.land; | ||
|
|
||
| import leets.land.view.InputView; | ||
| import leets.land.view.OutputView; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
|
|
||
| class UpdownApplicationTests { | ||
| UpdownApplication app; | ||
| private Controller controller; | ||
| private InputView inputViewMock; | ||
| private OutputView outputViewMock; | ||
|
|
||
|
|
||
| @Test | ||
| void contextLoads() { | ||
| public void setUp() { | ||
| controller = new Controller(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package leets.land.view; | ||
|
|
||
| import leets.land.domain.CharRange; | ||
| import leets.land.domain.Range; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class InputViewTest { | ||
| InputView inputView; | ||
| Range range; | ||
| @BeforeEach | ||
| void setUp() { | ||
| inputView = new InputView(); | ||
| } | ||
|
|
||
| @DisplayName("μ§μ λ²μ μ΄μΈμ λ²μ μ μ λ ₯νλ©΄ μμΈμ²λ¦¬") | ||
| @Test | ||
| void getVersionInput() { | ||
| IllegalArgumentException e = assertThrows(IllegalArgumentException.class, ()-> | ||
| inputView.validateVersion(0) ); | ||
| } | ||
|
|
||
| @DisplayName("λ²μ μΈμ μ«μκ° μ λ ₯λλ©΄ μμΈμ²λ¦¬") | ||
| @Test | ||
| void validateNumberRange() { | ||
| range = new Range(1,100); | ||
| IllegalArgumentException e = assertThrows(IllegalArgumentException.class, ()-> | ||
| inputView.validateNumberRange(range,101) ); | ||
| } | ||
|
|
||
| @DisplayName("λ²μ μΈμ μνλ²³μ΄ μ λ ₯λλ©΄ μμΈμ²λ¦¬") | ||
| @Test | ||
| void validateCharRange() { | ||
| CharRange charRange = new CharRange('A','z'); | ||
| IllegalArgumentException e = assertThrows(IllegalArgumentException.class, ()-> | ||
| inputView.validateCharRange(charRange,',') ); | ||
| } | ||
| @DisplayName("μνλ²³μ΄ λκ° μ λ ₯λλ©΄ μμΈμ²λ¦¬") | ||
| @Test | ||
| void validCharLength() { | ||
| String doubleString = "ab"; | ||
| IllegalArgumentException e = assertThrows(IllegalArgumentException.class, ()-> | ||
| inputView.validCharLength(doubleString)); | ||
| } | ||
| } |
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.
correctλ₯Ό -1λ‘ λ μ΄μ κ° λ¬΄μμΈκ°μ?
μλλ₯Ό νμ νκΈ° νλ κ² κ°μμ
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.
correctλ μ λ΅μ΄λΌλ μλ―Έμ λ³μμ λλ€.
1λ‘ λμλ€κ° νλ²μ μ λ΅μ΄ λλ νμμ λ°©μ§νκΈ° μν¨μ΄μμ΅λλ€!