-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] : 1차 세미나 과제 선택 구현 - 이모지 포함 글자수 계산 구현
- Loading branch information
1 parent
1e98bfc
commit 2ece0f0
Showing
4 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.sopt.week1; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class TextUtils { | ||
|
||
private static final Pattern graphemePattern = Pattern.compile("\\X"); | ||
private static final Matcher graphemeMatcher = graphemePattern.matcher(""); | ||
|
||
public static int getLengthOfBody(final String body) { | ||
if (body == null) { | ||
return 0; | ||
} | ||
|
||
graphemeMatcher.reset(body); | ||
|
||
int count = 0; | ||
while (graphemeMatcher.find()) { | ||
count++; | ||
} | ||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import org.junit.jupiter.api.*; | ||
import org.sopt.week1.TextUtils; | ||
|
||
@DisplayName("일기 글자 수 세기 테스트") | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
public class TextUtilsTest { | ||
|
||
@Test | ||
void 이모지는_한_개의_문자로_인식한다() { | ||
//given | ||
final String test1 = "😃행복한 하루였어요👍"; | ||
final String test2 = "🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻🤞🏻"; | ||
final int expected1 = 11; | ||
final int expected2 = 31; | ||
|
||
//when | ||
final int actual1 = TextUtils.getLengthOfBody(test1); | ||
final int actual2 = TextUtils.getLengthOfBody(test2); | ||
|
||
//then | ||
Assertions.assertEquals(actual1, expected1); | ||
Assertions.assertEquals(actual2, expected2); | ||
|
||
} | ||
} |