Skip to content

Commit

Permalink
[WIP] Add racing car TDD
Browse files Browse the repository at this point in the history
  • Loading branch information
ohahohah committed Feb 16, 2019
1 parent b3623b8 commit cc88f85
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
9 changes: 2 additions & 7 deletions tddExercise/src/racingCar/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ void goCar(int randomVal) {
}

private int getRandomVal() {
return (int)(Math.random() * 8 + 1);
return (int) (Math.random() * 8 + 1);
}

int calForwardCoord(int randomVal) {

return randomVal >=4? 1:0;
return randomVal >= 4 ? 1 : 0;
}

// // TODO test용 생성
// public void setCurrentCoord(int currentCoord) {
// this.currentCoord = currentCoord;
// }
}
5 changes: 5 additions & 0 deletions tddExercise/src/racingCar/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package racingCar;

public class Race {

}
20 changes: 20 additions & 0 deletions tddExercise/src/racingCar/RacingGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
* 자동차 경주 게임
Expand All @@ -27,6 +28,12 @@ int getTurn() {
}

public void doGame() {

String carNamee = scanCarNames();
int turn = scanTurn();
// 경주할 자동차 이름을 입력하세요(이름은 쉼표(,)를 기준으로 구분).
// 시도할 회수는 몇회인가요?

for (int i = 0; i < turn; i++) {
doTurnGame();
}
Expand All @@ -36,6 +43,19 @@ public void doGame() {
printResult();
}

private int scanTurn() {
return 0;
}

private String scanCarNames() {
Scanner scan = new Scanner(System.in); // 문자 입력을 인자로 Scanner 생성
System.out.println("경주할 자동차 이름을 입력하세요(이름은 쉼표(,)를 기준으로 구분).");

System.out.println("메시지를 입력하세요:");

return scan.nextLine();
}

void doTurnGame() {
for (int i = 0; i < carList.size(); i++) {
carList.get(i).goCar();
Expand Down
33 changes: 20 additions & 13 deletions tddExercise/test/racingCar/RacingGameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class RacingGameTest {

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"car01,car02,car03", 3}});
}

private RacingGame racingGame = null;

// TODO - Question - 공통 testcase value를 class field로 두어도 괜찮나?
private String carsName = "car01,car02,car03";
private int turn = 3;
private String carsName;
private int turn;

public RacingGameTest(String carsName, int turn) {
this.carsName = carsName;
this.turn = turn;

}

@Before
public void setUp() {
Expand Down Expand Up @@ -52,24 +68,15 @@ public void tearDown() {
}


//TODO 주어진_게임_회차만큼_진행하는지_확인
@Test
@Ignore
public void 주어진_게임_회차만큼_진행하는지_확인() {

int numberOfSingleGame = 3;

assertEquals(numberOfSingleGame, 3);

}

@Test
public void testDoGame() {

racingGame.doGame();
}

@Test
@Ignore
public void testDoSingleGame() {

racingGame.doTurnGame();
Expand Down

0 comments on commit cc88f85

Please sign in to comment.