-
Notifications
You must be signed in to change notification settings - Fork 0
Change test code #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| import kr.co.shineware.ds.trie.trie.doublearray.ahocorasick.AhoCorasickDoubleArrayTrie; | ||
| import kr.co.shineware.ds.trie.trie.doublearray.ahocorasick.model.Hit; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Ignore; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.*; | ||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.concurrent.*; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
|
|
@@ -45,46 +50,97 @@ public static void teardown() { | |
| } | ||
| } | ||
|
|
||
| // @Test | ||
| // public void testSequentialGet() { | ||
| // for (int i = 0; i < KEYS.length; i++) { | ||
| // // TODO: 2019-08-23 이 부분이 지금 정상적으로 test가 되어야 기존에 있는 인터페이스를 따라갈 수 있어요. | ||
| // final Map<String, Integer> result = dic.get(KEYS[i]); | ||
| // final Set<Integer> expectedResult = expectedResultSet(KEYS[i]); | ||
| // | ||
| // assertEquals(expectedResult, new HashSet<>(result.values())); | ||
| // } | ||
| // } | ||
|
|
||
| @Test | ||
| public void testSequentialGet() { | ||
| public void testSequentialGetModifiedByDennis() { | ||
| for (int i = 0; i < KEYS.length; i++) { | ||
| // TODO: 2019-08-23 이 부분이 지금 정상적으로 test가 되어야 기존에 있는 인터페이스를 따라갈 수 있어요. | ||
| final Map<String, Integer> result = dic.get(KEYS[i]); | ||
| final Set<Integer> expectedResult = expectedResultSet(KEYS[i]); | ||
| final List<Hit<Integer>> parseResult = dic.parseText(KEYS[i]); | ||
| final Set<Integer> actualResult = parseResult.stream() | ||
| .map(hitResult -> hitResult.value) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| final Set<Integer> expectedResult = new HashSet<>(); | ||
| final String targetValue = KEYS[i]; | ||
| for (int subStrLen = 1; subStrLen < targetValue.length() + 1; subStrLen++) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존 aho-corasick은 현재 노드에서 parent 노드를 계속 tracking하면서 key값을 알 수 있습니다. double-array aho-corasick에서도 parent를 tracking 가능한지 봐야합니다. 그게 안되면 근호님이 쓰신 코드와 같이 입력된 string에서 key에 해당하는 부분을 찾아내야하는데 이렇게 되면 기존 aho-corasick을 사용하고 있는 인터페이스 부분을 많이 수정해야할 것으로 보입니다.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 기존 구현과 더블 어레이 트라이의 내부 구현을 조금 더 봐야될 것 같아요~ |
||
| for (int subStrBeginIdx = 0; subStrBeginIdx + subStrLen <= targetValue.length(); subStrBeginIdx++) { | ||
| final String subStr = targetValue.substring(subStrBeginIdx, subStrBeginIdx + subStrLen); | ||
| expectedResult.add(Integer.parseInt(subStr)); | ||
| } | ||
| } | ||
|
|
||
| assertEquals(expectedResult, new HashSet<>(result.values())); | ||
| assertEquals(expectedResult, actualResult); | ||
| } | ||
| } | ||
|
|
||
| // @Test | ||
| // public void testConcurrentGet() throws ExecutionException, InterruptedException { | ||
| // final List<Future> futures = new ArrayList<>(); | ||
| // for (int i = 0; i < KEYS.length; i++) { | ||
| // final int index = i; | ||
| // futures.add(service.submit(new Callable<Set<Integer>>() { | ||
| // @Override | ||
| // public Set<Integer> call() throws Exception { | ||
| // return new HashSet<>(dic.get(KEYS[index]).values()); | ||
| // } | ||
| // })); | ||
| // } | ||
| // | ||
| // for (int i = 0; i < futures.size(); i++) { | ||
| // final Set<Integer> expectedResult = expectedResultSet(KEYS[i]); | ||
| // assertEquals(expectedResult, futures.get(i).get()); | ||
| // } | ||
| // } | ||
|
|
||
| @Test | ||
| public void testConcurrentGet() throws ExecutionException, InterruptedException { | ||
| public void testConcurrentGetModifiedByDennis() throws ExecutionException, InterruptedException { | ||
| final List<Future> futures = new ArrayList<>(); | ||
| for (int i = 0; i < KEYS.length; i++) { | ||
| final int index = i; | ||
| futures.add(service.submit(new Callable<Set<Integer>>() { | ||
| @Override | ||
| public Set<Integer> call() throws Exception { | ||
| return new HashSet<>(dic.get(KEYS[index]).values()); | ||
| return dic.parseText(KEYS[index]) | ||
| .stream() | ||
| .map(hitResult -> hitResult.value) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| for (int i = 0; i < futures.size(); i++) { | ||
| final Set<Integer> expectedResult = expectedResultSet(KEYS[i]); | ||
| final Set<Integer> expectedResult = new HashSet<>(); | ||
| final String targetValue = KEYS[i]; | ||
| for (int subStrLen = 1; subStrLen < targetValue.length() + 1; subStrLen++) { | ||
| for (int subStrBeginIdx = 0; subStrBeginIdx + subStrLen <= targetValue.length(); subStrBeginIdx++) { | ||
| final String subStr = targetValue.substring(subStrBeginIdx, subStrBeginIdx + subStrLen); | ||
| expectedResult.add(Integer.parseInt(subStr)); | ||
| } | ||
| } | ||
|
|
||
| assertEquals(expectedResult, futures.get(i).get()); | ||
| } | ||
| } | ||
|
|
||
| private static Set<Integer> expectedResultSet(final String str) { | ||
| final Set<Integer> resultSet = new HashSet<>(); | ||
|
|
||
| for (int subStrLen = 1; subStrLen < str.length() + 1; subStrLen++) { | ||
| for (int subStrBeginIdx = 0; subStrBeginIdx + subStrLen <= str.length(); subStrBeginIdx++) { | ||
| final String subStr = str.substring(subStrBeginIdx, subStrBeginIdx + subStrLen); | ||
| resultSet.add(Integer.parseInt(subStr)); | ||
| } | ||
| } | ||
|
|
||
| return resultSet; | ||
| } | ||
| // private static Set<Integer> expectedResultSet(final String str) { | ||
| // final Set<Integer> resultSet = new HashSet<>(); | ||
| // | ||
| // for (int subStrLen = 1; subStrLen < str.length() + 1; subStrLen++) { | ||
| // for (int subStrBeginIdx = 0; subStrBeginIdx + subStrLen <= str.length(); subStrBeginIdx++) { | ||
| // final String subStr = str.substring(subStrBeginIdx, subStrBeginIdx + subStrLen); | ||
| // resultSet.add(Integer.parseInt(subStr)); | ||
| // } | ||
| // } | ||
| // | ||
| // return resultSet; | ||
| // } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 내용을 명확하게 안 했네요. dic.get(KEYS[i])의 리턴 형태가 Map<String,Integer> 형태가 되어야 합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test code의 동작을 보면 Key 값이 "10"인 경우 expected value는 0, 1, 10으로 보이는데요. 이 경우 Map으로 반환을 받기 위해서는 MultiValueMap을 사용해야 할까요? 다시 말해서 Key 하나에 대해서 value가 여러 개인 Map의 반환에 대한 인터페이스 정의가 어떻게 되나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KEYS[i]값이10인 경우에는 result 값에{ 0 : 0 },{1 : 1},{10 : 10}이 들어가게 됩니다.현재 test에서는 key 값을 value 값과 같은 값으로 주었습니다. 그러나 value 값을
key value * 2로 주었다고 가정하면 이 경우에는 result 값에{ 0 : 0 },{1 : 2},{10 : 20}이 들어가게 될 것입니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 이해했습니다! 감사합니다