[문제풀이] 프로그래머스 - 암호해독 + TDD 연습

조히고닝·2023년 2월 23일
0

[문제풀이] 프로그래머스 - 암호해독

문제풀이


class Solution {
    public String solution(String cipher, int code) {
        String answer = "";
        for(int i=1; i<=cipher.length()/code; i++){
            answer+=cipher.toCharArray()[code*i-1];
        }
        return answer;
    }
}

테스트 코드 작성

class SolutionTest {

    @Test
    void solution() {
        assertThat(new Solution().solution("dfjardstddetckdaccccdegk", 4)).isEqualTo("attack");
    }
    @Test
    void solution2() {
        assertThat(new Solution().solution("pfqallllabwaoclk", 2)).isEqualTo("fallback");
    }
}

문제 풀이 내부에서 메인함수 만들고 매개변수 넘겨줄 수도 있지만 테스트 코드 만드는거 연습해보자

0개의 댓글

Powered by GraphCDN, the GraphQL CDN