Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

클래스 별로 코드를 나눠봤습니다. #15

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Conversation

GHeeJeon
Copy link
Collaborator

나눠 '만' 봤습니다. 일단은요!

keyList 와 valueList 로 나누어 저장

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* Hello world!
*/
import static input.Reader.logCount;

public class App {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드를 옮기다 문제가 생길까봐... Parser 부분의 코드만 메인에 남겨두었습니다!
실제 Parser 에 들어있는 코드와 동일합니다.

while (myReader.hasNextLine()) {
data = myReader.nextLine();
Parser parser = new Parser();
parser.parse(data);
Copy link
Collaborator Author

@GHeeJeon GHeeJeon Aug 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read - parse - write 의 과정 거치기

  1. 데이터를 한 줄씩 읽어 오면서
    parse 내에서 StringUtils.substringsBetween() 등을 이용해 데이터를 가공(ex. 이용한 브라우저 뽑아내기)한 후,
  2. while 문 밖에서, 즉 read 의 역할이 모두 끝난 후에
    필요한 연산이나 정렬 등으로 한 번 더 처리(ex. 브라우저 빈도 수 정렬 및 사용비율 계산)해준 후
  3. 결과값을 write 에서 쓰기

read(read 내부에서 parse) - write 의 과정 거치기

  1. read 에서 while 문을 돌며 데이터를 받아오는 동시에 모든 가공처리를 하고
  2. 결과값을 write 에서 쓰기

둘 중 어느 방향으로 가는 게 더 좋을까요...?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while 문이 끝난 후 정렬 연산을 수행하는 게 더 효율적으로 보입니다. while 문을 돌면서 가공처리를 하게되면 매번 정렬을 수행해야하니까요!

}

public static void getWebBrowser(Map<String, Integer> orderedWebBrowserMap) {
final Iterator<Map.Entry<String, Integer>> entryIteratorWebBrowser = orderedWebBrowserMap.entrySet().iterator();
Copy link
Collaborator Author

@GHeeJeon GHeeJeon Aug 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

웹 브라우저의 이름(key)과 사용된 횟수(value)를 둘 다 저장하기 위해 두 개의 ArrayList 를 선언했습니다!

while(entryIteratorWebBrowser.hasNext()) {
 entryWebBrowserKeyList.add(entryIteratorWebBrowser.next().getKey());
}

로 웹 브라우저의 이름(key)을 저장했으나, 횟수를 어떻게 저장해야 할지에 대해 고민했습니다.
같은 방식으로 while 문을 한 번 더 돌리자니, 이미 끝까지 돌려버려 NULL 을 가리키게 되더라구요.

그래서 새로운 이터레이터 entryIteratorWebBrowser1 을 만들어
entryIteratorWebBrowser1.hasNext() 로 while 문을 돌려 사용된 횟수(value)를 리스트에 저장했습니다.
이터레이터를 일회용으로 쓰고 버리는 느낌이라... 더 효율적인 방법이 있을 것 같습니다...
다른 좋은 방법이 없을까요...?


// given
// when
// then
@Test
public void shouldAnswerWithTrue()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 코드를 짜야 하는데... 어디서부터 손을 대야 할지 모르겠습니다...

입력(file 읽기)에 대한 검증부터 하면 되나요...?
input.log 자체가 존재하는지부터 시작해서
한 줄씩 읽어들인 로그에서 추출한 값이 모두 유효한지 (ex. apikey 가 요구사항 대로 숫자+영어로 이루어진 네 자리로 이루어져 있는지)
추출한 값을 토대로 정렬을 했다면 정상적으로 정렬이 되었는지
각 인스턴스가 NULL 을 가리킬 일이 없는지에 대해 모두 검사해야 하는지, 만약 검사해야 한다면
들어오는 매개변수의 타입이 int string map 등 다양할 텐데 모든 자료형에 대한 테스트를 따로 만들어야 할지
output.log 가 잘 만들어졌는지(혹은 존재하는지), 원하는 데이터를 빠짐없이 출력했는지(ex. 서버코드 출력이 누락되었다거나)...

어떻게 시작하면 좋을까요ㅠㅠ

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트하기 쉬운 코드부터 만들면 됩니다.
기능하나당 메소드하나라고 생각해보면 쉽습니다. fileReader로 예를 들어볼께요.
ex)

  1. fileReader 는 파일을 읽는데 도움을 주는 클래스입니다. 처음 필요한 메소드는 파일이 존재하는지 여부를 체크하는 메소드입니다. 파일이 존재하지 않으면 에러를 발생시켜야하니까요. 파일이 존재하는지 체크하는 메소드를 테스트합니다.

  2. 파일이 존재한다면 존재하는 파일의 문장을 한줄씩 잘 읽어 들이는지 테스트합니다.

이런식으로 진행해가는 거죠. 쉬운 것부터 나눠서 시작합니다. 그리고 메소드 하나에 기능이 너무 많아 테스트가 어렵거나 불가능하다면 작은 단위의 기능으로 메소드를 추출해서 테스트해보는 것을 추천합니다.

while (myReader.hasNextLine()) {
data = myReader.nextLine();
Parser parser = new Parser();
parser.parse(data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while 문이 끝난 후 정렬 연산을 수행하는 게 더 효율적으로 보입니다. while 문을 돌면서 가공처리를 하게되면 매번 정렬을 수행해야하니까요!

Comment on lines 21 to 24
while (myReader.hasNextLine()) {
data = myReader.nextLine();
Parser parser = new Parser();
parser.parse(data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parser가 Reader와 너무 강결합이 되어있는 것 같습니다.
Parser를 Reader생성할 때 생성자로 받는건 어떤가요? Reader를 사용하는 사람이 Parser를 지정할 수 있게요.


// given
// when
// then
@Test
public void shouldAnswerWithTrue()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트하기 쉬운 코드부터 만들면 됩니다.
기능하나당 메소드하나라고 생각해보면 쉽습니다. fileReader로 예를 들어볼께요.
ex)

  1. fileReader 는 파일을 읽는데 도움을 주는 클래스입니다. 처음 필요한 메소드는 파일이 존재하는지 여부를 체크하는 메소드입니다. 파일이 존재하지 않으면 에러를 발생시켜야하니까요. 파일이 존재하는지 체크하는 메소드를 테스트합니다.

  2. 파일이 존재한다면 존재하는 파일의 문장을 한줄씩 잘 읽어 들이는지 테스트합니다.

이런식으로 진행해가는 거죠. 쉬운 것부터 나눠서 시작합니다. 그리고 메소드 하나에 기능이 너무 많아 테스트가 어렵거나 불가능하다면 작은 단위의 기능으로 메소드를 추출해서 테스트해보는 것을 추천합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants