오늘(250209) 정보처리기사 필기시험을 보고 왔다. 시험을 제출하면 가채점 결과를 보여주는데, 68점이 나왔다. 오예! 😁 찾아보니 가채점 점수에서 오르면 올랐지 내려가지는 않는다고 그래서 합격권인 듯 하다. 이제는 실기 준비를 해야 한다. 몇 주 내내 한파가 계속돼서 아침에 일어나기가 너무 힘들다. SSAFY 처음 시작할 때만 해도 뭐든 열심히 해서 갓생살겠다 다짐했지만,,, 얼마 못 가 게을러지는 날 보고는 한다. 나란 사람 간사한 사람,,, 여하튼 계속되는 한파로 출근이 싫은 이번 주를 되돌아본다.
원래는 test 코드 디렉토리를 분리해서 관리했다. 그런데 Solution 클래스가 public 클래스가 아니다 보니 사용할 수가 없었다. 그래서 테스트 코드 디렉토리를 제거했다. 그리고 똑같은 패키지에 풀이 로직과 테스트 로직을 같이 위치시켰다. 분리하라고 IDE에서 잔소리를 하지만 더 좋은 방법을 아직은 못 찾았다.
- main.BJ9095
- SolutionTest.java
- Main.java
package main.BJ9095;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.*;
class SolutionTest {
@ParameterizedTest(name = "input {0} : expected {1}")
@CsvSource({
"4, 7",
"7, 44",
"10, 274"
})
void test(int input, int expected) {
// given
Solution s = new Solution();
int[] expectedArray = {expected}; // Create an array for expected value
// when
int[] result = s.solution(new int[]{input});
// then
assertArrayEquals(expectedArray, result); // Compare arrays
}
}
package main.BJ9095;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
new Main().run();
}
private void run() {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Solution s = new Solution();
s.solution(readInput(br));
System.out.println(s.getAnswer());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private int[] readInput(BufferedReader br) throws IOException {
int len = Integer.parseInt(br.readLine());
int[] result = new int[len];
for (int i = 0; i < len; i++) {
result[i] = Integer.parseInt(br.readLine());
}
return result;
}
}
class Solution {
private int[] field;
private int[] result;
public int[] solution(int[] targets) {
init(targets);
result = new int[targets.length]; // Initialize result here
for (int i = 0; i < targets.length; i++) {
result[i] = field[targets[i]];
}
return result;
}
private void init(int[] targets) {
this.field = new int[12];
this.result = new int[targets.length];
field[1] = 1;
field[2] = 2;
field[3] = 4;
for (int i = 4; i < field.length; i++) {
field[i] = field[i - 1] + field[i - 2] + field[i - 3];
}
}
public String getAnswer() {
StringBuilder answer = new StringBuilder();
for (int target : result) {
answer.append(target).append("\n");
}
return answer.toString();
}
}