Skip to content

Commit

Permalink
전략패턴 테스트 + 부산 do369 룰 부분 로직상 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
silano08 committed Apr 21, 2024
1 parent 33de267 commit ef6b5a8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/JavaPractice/ThreeSixNineGame/Rule/Busan369.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ public String do369(int number) {
String numStr = Integer.toString(number);

String result = "";
for(int i=0; i<numStr.length(); i++){
if(numStr.contains("3") || numStr.contains("6") || numStr.contains("9")) result+= "clap";
for (int i = 0; i < numStr.length(); i++) {
char c = numStr.charAt(i);
if (c == '3' || c == '6' || c == '9') {
result += "clap";
}
}

if(result.equals("")){
// '3', '6', '9' 가 한번도 포함되지 않았다면, 숫자를 문자열로 반환
if (result.isEmpty()) {
return numStr;
}else{
return result;
}
return result;
}
}
34 changes: 34 additions & 0 deletions test/JavaPractice/ThreeSixNineGame/ThreeSixNineGameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package JavaPractice.ThreeSixNineGame;

import JavaPractice.ThreeSixNineGame.Rule.Busan369;
import JavaPractice.ThreeSixNineGame.Rule.Seoul369;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ThreeSixNineGameTest {

@Test
void playGame() {
}

@Test
void ruleChangeTest(){

Context context = new Context();

// 서울의 룰로하다가

context.set369Rule(new Seoul369());
assertEquals("clap", context.do369(33));
assertEquals("clap", context.do369(369));

// 부산의 룰로 체인지

context.set369Rule(new Busan369());
assertEquals("clapclapclap", context.do369(369));
assertEquals("clapclap", context.do369(33));

}

}

0 comments on commit ef6b5a8

Please sign in to comment.