Coder Social home page Coder Social logo

baseball's Introduction

Baseball Game (TDD 실습)

Baseball Game 실습 소개

Baseball Game 규칙

  • 0~9까지의 숫자 중 임의의 다른 세 자리의 숫자를 불러서, 상대방이 맞추는 게임이다.
    • 사용되는 숫자는 0~9까지의 서로 다른 숫자이다.
    • 숫자는 맞지만 위치가 틀렸을 경우에는 Ball
    • 숫자와 위치가 모두 맞으면 Strike
  • Example : question이 "123"일 경우
    • guess(“123”) -> solved=true, strikes=3, balls=0
    • guess(“456”) -> solved=false, strikes=0, balls=0
    • guess(“129”) -> solved=false, strikes=2, balls=0
    • guess(“240”) -> solved=false, strikes=0, balls=1
    • guess(“321”) -> solved=false, strikes=1, balls=2

Baseball Game 구현

  • 답에 대한 return은 아래 속성을 가지는 객체로 한다.
    • boolean solved
    • int strikes
    • int balls
  • 아래의 경우 예외처리 후 게임을 종료한다.
    • 입력값이 없을 경우
    • 자리수가 세 자리가 아닐 경우
    • 숫자 외의 문자가 입력될 경우
    • 중복된 숫자가 입력될 경우
  • 테스트 케이스 예시
    • 입력값이 없을 경우
    • 입력값 자리수가 세자리가 아닐 경우 ("12", "1234")
    • 입력값에 숫자 외의 문자가 입력될 경우 ("A12")
    • 입력값에 중복된 숫자가 입력될 경우 ("112")
    • 숫자 세개가 전부 일치 할 경우 (question : "123", guess : "123")
    • 숫자 세개가 전부 일치 하지 않을 경우 (question : "123", guess : "456")
    • 스트라이크만 있을 경우 (question : "123", guess : "178")
    • 볼만 있을 경우 (question : "123", guess : "561")
    • 볼과 스트라이크가 함께 있을 경우 (question : "123", guess : "136")

실습방법

  1. 가장 쉽게 구현할 수 있는 테스트부터 시작한다.
  2. 실패하는 테스트 케이스를 만든다. (Red)
  3. 실패하는 테스트 케이스를 성공하도록 최소한의 소스를 수정한다. (Green) 필요하다면 하드코딩 한다.
  4. 리팩토링이 필요하다면 수행한다. (Refactoring)
  • 중복을 제거한다. 비슷한 중복을 완전한 중복으로 바꾼다.
  • Extract method, Extract to local variable, Inline local variable….
  1. 새로운 실패하는 테스트 케이스를 만든다
  2. 1~5 반복을 통해 구체화되는 테스트케이스를 이용하여 일반화되는 소스코드를 작성한다.

Eclipse 환경설정

Hamcrest 설정

  • Windows -> Preperence 메뉴
  • Java -> Editor -> Content Assist -> Favorites 항목
  • "org.junit.Assert", "org.hamcrest.CoreMatchers"

Pair Programming

드라이버/네이게이터

  • 드라이버 - 소스코드를 타이핑 한다.
  • 네비게이터 - 실시간으로 코드를 리뷰하면서 드라이버를 가이드 한다.

핑퐁

  • 한명은 실패하는 테스트 케이스를 작성하고, 나머지 한명은 테스트를 구현하기 위한 성공코드를 작성한다.

참고 API

String class

public int length()
public char charAt(int index)
public int indexOf(int ch)

baseball's People

Contributors

youme0123 avatar youmebae avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.