Skip to content

Commit

Permalink
test: 테스트 한글화와 테스트 커버리지 개선 (#81)
Browse files Browse the repository at this point in the history
* test: 테스트 한글화

* test: Add test case for empty string input in josa function

* test: Add test case for empty string input in removeLastHangulCharacter function

* test: Add tests for getFirstConsonants function
  • Loading branch information
gwansikk committed Apr 29, 2024
1 parent 18085b6 commit 36313f9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 45 deletions.
19 changes: 10 additions & 9 deletions src/_internal/hangul.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { binaryAssembleHangulCharacters, binaryAssembleHangul, isHangulAlphabet, isHangulCharacter } from './hangul';

describe('isHangul*', () => {
it('isHangulCharacter는 완성된 한글 문자를 받으면 true를 반환한다', () => {
it('isHangulCharacter는 완성된 한글 문자를 받으면 true를 반환한다.', () => {
expect(isHangulCharacter('가')).toBe(true);
expect(isHangulCharacter('값')).toBe(true);
expect(isHangulCharacter('ㄱ')).toBe(false);
expect(isHangulCharacter('ㅏ')).toBe(false);
expect(isHangulCharacter('a')).toBe(false);
});
it('isHangulAlphabet은 조합되지않은 한글 문자를 받으면 true를 반환한다', () => {

it('isHangulAlphabet은 조합되지않은 한글 문자를 받으면 true를 반환한다.', () => {
expect(isHangulAlphabet('가')).toBe(false);
expect(isHangulAlphabet('값')).toBe(false);
expect(isHangulAlphabet('ㄱ')).toBe(true);
Expand Down Expand Up @@ -47,13 +48,13 @@ describe('binaryAssembleHangulCharacters', () => {
expect(binaryAssembleHangulCharacters('깎', 'ㅏ')).toEqual('까까');
});

it('문법에 맞지 않는 문자를 조합하면 단순 Join 한다 (문법 순서 틀림)', () => {
it('문법에 맞지 않는 문자를 조합하면 단순 Join 한다. (문법 순서 틀림)', () => {
expect(binaryAssembleHangulCharacters('ㅏ', 'ㄱ')).toEqual('ㅏㄱ');
expect(binaryAssembleHangulCharacters('까', 'ㅃ')).toEqual('까ㅃ');
expect(binaryAssembleHangulCharacters('ㅘ', 'ㅏ')).toEqual('ㅘㅏ');
});

it('순서대로 입력했을 때 조합이 불가능한 문자라면 단순 Join 한다', () => {
it('순서대로 입력했을 때 조합이 불가능한 문자라면 단순 Join 한다.', () => {
expect(binaryAssembleHangulCharacters('뼈', 'ㅣ')).toEqual('뼈ㅣ');
});

Expand Down Expand Up @@ -85,24 +86,24 @@ describe('binaryAssembleHangulCharacters', () => {
});

describe('binaryAssembleHangul', () => {
it('문장과 모음을 조합하여 다음 글자를 생성한다', () => {
it('문장과 모음을 조합하여 다음 글자를 생성한다.', () => {
expect(binaryAssembleHangul('저는 고양이를 좋아합닏', 'ㅏ')).toEqual('저는 고양이를 좋아합니다');
});

it('문장과 자음을 조합하여 홑받침을 생성한다', () => {
it('문장과 자음을 조합하여 홑받침을 생성한다.', () => {
expect(binaryAssembleHangul('저는 고양이를 좋아하', 'ㅂ')).toEqual('저는 고양이를 좋아합');
});

it('문장과 자음을 조합하여 겹받침을 생성한다', () => {
it('문장과 자음을 조합하여 겹받침을 생성한다.', () => {
expect(binaryAssembleHangul('저는 고양이를 좋아합', 'ㅅ')).toEqual('저는 고양이를 좋아핪');
});

it('조합이 불가능한 자음이 입력되면 단순 Join 한다', () => {
it('조합이 불가능한 자음이 입력되면 단순 Join 한다.', () => {
expect(binaryAssembleHangul('저는 고양이를 좋아합', 'ㄲ')).toEqual('저는 고양이를 좋아합ㄲ');
expect(binaryAssembleHangul('저는 고양이를 좋아합', 'ㅂ')).toEqual('저는 고양이를 좋아합ㅂ');
});

it('조합이 불가능한 모음이 입력되면 단순 Join 한다', () => {
it('조합이 불가능한 모음이 입력되면 단순 Join 한다.', () => {
expect(binaryAssembleHangul('저는 고양이를 좋아하', 'ㅏ')).toEqual('저는 고양이를 좋아하ㅏ');
expect(binaryAssembleHangul('저는 고양이를 좋아합니다', 'ㅜ')).toEqual('저는 고양이를 좋아합니다ㅜ');
});
Expand Down
14 changes: 7 additions & 7 deletions src/chosungIncludes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ import { chosungIncludes } from './chosungIncludes';

describe('chosungIncludes', () => {
describe('초성이 포함되어있다고 판단되는 경우', () => {
it('should return true when "ㅍㄹㅌ" is entered for searching "프론트엔드"', () => {
it('"ㅍㄹㅌ" 문자열로 "프론트엔드"를 검색하면 true를 반환한다.', () => {
expect(chosungIncludes('프론트엔드', 'ㅍㄹㅌ')).toBe(true);
});

it('should return true when "ㅍㄹㅌ" is entered for searching "00프론트엔드"', () => {
it('"ㅍㄹㅌ" 문자열로 "00프론트엔드"를 검색하면 true를 반환한다.', () => {
expect(chosungIncludes('00프론트엔드', 'ㅍㄹㅌ')).toBe(true);
});

it('should return true when "ㅍㄹㅌㅇㄷㄱㅂㅈ" is entered for searching "프론트엔드 개발자"', () => {
it('"ㅍㄹㅌㅇㄷㄱㅂㅈ" 문자열로 "프론트엔드 개발자"를 검색하면 true를 반환한다.', () => {
expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷㄱㅂㅈ')).toBe(true);
});

it('should return true when "ㅍㄹㅌㅇㄷ ㄱㅂㅈ" is entered for searching "프론트엔드 개발자"', () => {
it('"ㅍㄹㅌㅇㄷ ㄱㅂㅈ" 문자열로 "프론트엔드 개발자"를 검색하면 true를 반환한다.', () => {
expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷ ㄱㅂㅈ')).toBe(true);
});
});

describe('초성이 포함되어있다고 판단되지 않는 경우', () => {
it('should return false when "ㅍㅌ" is entered for searching "프론트엔드"', () => {
it('"ㅍㅌ" 문자열로 "프론트엔드"를 검색하면 false를 반환한다.', () => {
expect(chosungIncludes('프론트엔드', 'ㅍㅌ')).toBe(false);
});

it('should return false when "ㅍㄹㅌㅇㄷ ㄱㅂㅈ" is entered for searching " "', () => {
it('빈 문자열로 "프론트엔드 개발자"를 검색하면 false를 반환한다.', () => {
expect(chosungIncludes('프론트엔드 개발자', ' ')).toBe(false);
});

it('should return false when "푸롴트" is entered for searching "프론트엔드" as it does not only include the initial consonants.', () => {
it('"푸롴트" 문자열로 "프론트엔드"를 검색하면 초성으로만 구성되어 있지 않아 false를 반환한다.', () => {
expect(chosungIncludes('프론트엔드', '푸롴트')).toBe(false);
});
});
Expand Down
25 changes: 14 additions & 11 deletions src/josa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Hangul', () => {
expect(josa('바깥', '으로/로')).toBe('바깥으로');
expect(josa('내부', '으로/로')).toBe('내부로');
});
it('방향의 격조사 ㄹ 받침 예외처리', () => {
it('방향의 격조사 ㄹ 받침 예외 처리', () => {
expect(josa('지름길', '으로/로')).toBe('지름길로');
});
it('비교의 격조사', () => {
Expand All @@ -45,34 +45,37 @@ describe('Hangul', () => {
expect(josa('사과', '이에요/예요')).toBe('사과예요');
expect(josa('책', '이에요/예요')).toBe('책이에요');
});
it('서술격조사와 종결어미, "이" 로 끝나는 단어 예외처리', () => {
it('서술격조사와 종결어미, "이" 로 끝나는 단어 예외 처리', () => {
expect(josa('때밀이', '이에요/예요')).toBe('때밀이예요');
});
it('지위나 신분 또는 자격을 나타내는 위격조사', () => {
expect(josa('학생', '으로서/로서')).toBe('학생으로서');
expect(josa('부모', '으로서/로서')).toBe('부모로서');
});
it('지위나 신분 또는 자격을 나타내는 위격조사 ㄹ 받침 예외처리', () => {
it('지위나 신분 또는 자격을 나타내는 위격조사 ㄹ 받침 예외 처리', () => {
expect(josa('라이벌', '으로서/로서')).toBe('라이벌로서');
});
it('수단의 의미를 나타내는 도구격조사', () => {
expect(josa('토큰', '으로써/로써')).toBe('토큰으로써');
expect(josa('함수', '으로써/로써')).toBe('함수로써');
});
it('수단의 의미를 나타내는 도구격조사 ㄹ 받침 예외처리', () => {
it('수단의 의미를 나타내는 도구격조사 ㄹ 받침 예외 처리', () => {
expect(josa('건물', '으로써/로써')).toBe('건물로써');
});
it('어떤 행동의 출발점이나 비롯되는 대상임을 나타내는 격 조사', () => {
expect(josa('역삼동', '으로부터/로부터')).toBe('역삼동으로부터');
expect(josa('저기', '으로부터/로부터')).toBe('저기로부터');
});
it('어떤 행동의 출발점이나 비롯되는 대상임을 나타내는 격 조사 ㄹ 받침 예외처리', () => {
it('어떤 행동의 출발점이나 비롯되는 대상임을 나타내는 격 조사 ㄹ 받침 예외 처리', () => {
expect(josa('동굴', '으로부터/로부터')).toBe('동굴로부터');
});
it('단어가 빈 문자열일 경우 빈 문자열을 반환한다.', () => {
expect(josa('', '이/가')).toBe('');
});
});

describe('josa.pick', () => {
it('첫 번째 매개변수가 빈 문자열이라면 옵션중 첫 번째 값을 반환한다', () => {
it('첫 번째 매개변수가 빈 문자열이라면 옵션 중 첫 번째 값을 반환한다.', () => {
expect(josa.pick('', '이/가')).toBe('이');
});
it('주격조사', () => {
Expand All @@ -91,7 +94,7 @@ describe('Hangul', () => {
expect(josa.pick('바깥', '으로/로')).toBe('으로');
expect(josa.pick('내부', '으로/로')).toBe('로');
});
it('방향의 격조사 ㄹ 받침 예외처리', () => {
it('방향의 격조사 ㄹ 받침 예외 처리', () => {
expect(josa.pick('지름길', '으로/로')).toBe('로');
});
it('비교의 격조사', () => {
Expand All @@ -118,28 +121,28 @@ describe('Hangul', () => {
expect(josa.pick('사과', '이에요/예요')).toBe('예요');
expect(josa.pick('책', '이에요/예요')).toBe('이에요');
});
it('서술격조사와 종결어미, "이" 로 끝나는 단어 예외처리', () => {
it('서술격조사와 종결어미, "이" 로 끝나는 단어 예외 처리', () => {
expect(josa.pick('때밀이', '이에요/예요')).toBe('예요');
});
it('지위나 신분 또는 자격을 나타내는 위격조사', () => {
expect(josa.pick('학생', '으로서/로서')).toBe('으로서');
expect(josa.pick('부모', '으로서/로서')).toBe('로서');
});
it('지위나 신분 또는 자격을 나타내는 위격조사 ㄹ 받침 예외처리', () => {
it('지위나 신분 또는 자격을 나타내는 위격조사 ㄹ 받침 예외 처리', () => {
expect(josa.pick('라이벌', '으로서/로서')).toBe('로서');
});
it('수단의 의미를 나타내는 도구격조사', () => {
expect(josa.pick('토큰', '으로써/로써')).toBe('으로써');
expect(josa.pick('함수', '으로써/로써')).toBe('로써');
});
it('수단의 의미를 나타내는 도구격조사 ㄹ 받침 예외처리', () => {
it('수단의 의미를 나타내는 도구격조사 ㄹ 받침 예외 처리', () => {
expect(josa.pick('건물', '으로써/로써')).toBe('로써');
});
it('어떤 행동의 출발점이나 비롯되는 대상임을 나타내는 격 조사', () => {
expect(josa.pick('역삼동', '으로부터/로부터')).toBe('으로부터');
expect(josa.pick('저기', '으로부터/로부터')).toBe('로부터');
});
it('어떤 행동의 출발점이나 비롯되는 대상임을 나타내는 격 조사 ㄹ 받침 예외처리', () => {
it('어떤 행동의 출발점이나 비롯되는 대상임을 나타내는 격 조사 ㄹ 받침 예외 처리', () => {
expect(josa.pick('동굴', '으로부터/로부터')).toBe('로부터');
});
});
Expand Down
7 changes: 5 additions & 2 deletions src/removeLastHangulCharacter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { removeLastHangulCharacter } from './removeLastHangulCharacter';

describe('removeLastHangulCharacter', () => {
it('마지막 문자가 겹받침인 경우 홑받침으로 바꾼다', () => {
it('마지막 문자가 겹받침인 경우 홑받침으로 바꾼다.', () => {
expect(removeLastHangulCharacter('안녕하세요 값')).toBe('안녕하세요 갑');
});
it('마지막 문자가 초성과 중성의 조합으로 끝날 경우 초성만 남긴다', () => {
it('마지막 문자가 초성과 중성의 조합으로 끝날 경우 초성만 남긴다.', () => {
expect(removeLastHangulCharacter('프론트엔드')).toBe('프론트엔ㄷ');
});
it('마지막 문자가 초성과 중성과 종성의 조합으로 끝날 경우 초성과 중성이 조합된 문자만 남긴다.', () => {
expect(removeLastHangulCharacter('일요일')).toBe('일요이');
expect(removeLastHangulCharacter('깎')).toBe('까');
});
it('빈 문자열일 경우 빈 문자열을 반환한다.', () => {
expect(removeLastHangulCharacter('')).toBe('');
});
});
52 changes: 36 additions & 16 deletions src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
canBeJongsung,
canBeJungsung,
getChosung,
getFirstConsonants,
hasBatchim,
hasProperty,
hasSingleBatchim,
Expand All @@ -11,22 +12,22 @@ import {

describe('hasBatchim', () => {
describe('받침이 있다고 판단되는 경우', () => {
it('should return true for the character "값"', () => {
it('"값" 문자에서 받침이 있으므로 true를 반환한다.', () => {
expect(hasBatchim('값')).toBe(true);
});
it('should return true for the character "공"', () => {
it('"공" 문자에서 받침이 있으므로 true를 반환한다.', () => {
expect(hasBatchim('공')).toBe(true);
});
it('should return true for the character "읊"', () => {
it('"읊" 문자에서 받침이 있으므로 true를 반환한다.', () => {
expect(hasBatchim('읊')).toBe(true);
});
});

describe('받침이 없다고 판단되는 경우', () => {
it('should return false for the character "토"', () => {
it('"토" 문자에서 받침이 없으므로 false를 반환한다.', () => {
expect(hasBatchim('토')).toBe(false);
});
it('should return false for the character "서"', () => {
it('"서" 문자에서 받침이 없으므로 false를 반환한다.', () => {
expect(hasBatchim('서')).toBe(false);
});
});
Expand Down Expand Up @@ -54,40 +55,59 @@ describe('hasSingleBatchim', () => {
});

describe('getChosung', () => {
it('should extract the initial consonants "ㅅㄱ" from the word "사과"', () => {
it('"사과" 단어에서 초성 "ㅅㄱ"을 추출한다.', () => {
expect(getChosung('사과')).toBe('ㅅㄱ');
});
it('should extract the initial consonants "ㅍㄹㅌㅇㄷ" from the word "프론트엔드"', () => {
it('"프론트엔드" 단어에서 초성 "ㅍㄹㅌㅇㄷ"을 추출한다.', () => {
expect(getChosung('프론트엔드')).toBe('ㅍㄹㅌㅇㄷ');
});
it('should extract the initial consonants "ㄴㅈ" from the consonants "ㄴㅈ"', () => {
it('"ㄴㅈ" 문자에서 초성 "ㄴㅈ"을 추출한다.', () => {
expect(getChosung('ㄴㅈ')).toBe('ㄴㅈ');
});
it('should extract the initial consonants "ㄹㅇㅌ" from the word "리액트"', () => {
it('"리액트" 단어에서 초성 "ㄹㅇㅌ"을 추출한다.', () => {
expect(getChosung('리액트')).toBe('ㄹㅇㅌ');
});

it('should extract the initial consonants "ㄸㅇ ㅆㄱ" from the phrase "띄어 쓰기"', () => {
it('"띄어 쓰기" 문장에서 초성 "ㄸㅇ ㅆㄱ"을 추출한다.', () => {
expect(getChosung('띄어 쓰기')).toBe('ㄸㅇ ㅆㄱ');
});
});

describe('getFirstConsonants', () => {
it('"사과" 단어에서 초성 "ㅅㄱ"을 추출한다.', () => {
expect(getFirstConsonants('사과')).toBe('ㅅㄱ');
});
it('"프론트엔드" 단어에서 초성 "ㅍㄹㅌㅇㄷ"을 추출한다.', () => {
expect(getFirstConsonants('프론트엔드')).toBe('ㅍㄹㅌㅇㄷ');
});
it('"ㄴㅈ" 문자에서 초성 "ㄴㅈ"을 추출한다.', () => {
expect(getFirstConsonants('ㄴㅈ')).toBe('ㄴㅈ');
});
it('"리액트" 단어에서 초성 "ㄹㅇㅌ"을 추출한다.', () => {
expect(getFirstConsonants('리액트')).toBe('ㄹㅇㅌ');
});

it('"띄어 쓰기" 문장에서 초성 "ㄸㅇ ㅆㄱ"을 추출된다.', () => {
expect(getFirstConsonants('띄어 쓰기')).toBe('ㄸㅇ ㅆㄱ');
});
});

describe('hasValueInReadOnlyStringList', () => {
const testReadonlyList = ['ㄱ', 'ㄴ', 'ㄷ'] as const;

it('should return true if an element exists in a read-only string list', () => {
it('read-only 문자열 리스트에 요소가 존재한다면 true를 반환한다.', () => {
const testValue = 'ㄱ';

expect(hasValueInReadOnlyStringList(testReadonlyList, testValue)).toBeTruthy();
});

it('should return false if an element does not exist in a read-only string list', () => {
it('read-only 문자열 리스트에 요소가 존재하지 않으면 false를 반환한다.', () => {
const testValue = 'ㄹ';

expect(hasValueInReadOnlyStringList(testReadonlyList, testValue)).toBeFalsy();
});

it('should narrow the type of the second argument if it is included in a read-only string list', () => {
it('read-only 문자열 리스트에 요소가 존재한다면 두 번째 인자의 타입을 좁힌다.', () => {
const testValue = 'ㄱ' as string;

if (hasValueInReadOnlyStringList(testReadonlyList, testValue)) {
Expand All @@ -101,19 +121,19 @@ describe('hasValueInReadOnlyStringList', () => {
describe('hasProperty', () => {
const testObj = { : 'ㄱ', : 'ㄴ', : 'ㄷ' } as const;

it('should return true if a property exists in a object', () => {
it('객체에 속성이 존재하면 true를 반환한다.', () => {
const testKey = 'ㄱ';

expect(hasProperty(testObj, testKey)).toBeTruthy();
});

it('should return false if a property does not exist in a object', () => {
it('객체에 속성이 존재하지 않으면 false를 반환한다.', () => {
const testKey = 'ㄹ';

expect(hasProperty(testObj, testKey)).toBeFalsy();
});

it('should narrow the type of the second argument if it is included in a object', () => {
it('객체에 속성이 존재한다면 두 번째 인자의 타입을 좁힌다.', () => {
const testKey = 'ㄱ' as string;

if (hasProperty(testObj, testKey)) {
Expand Down

0 comments on commit 36313f9

Please sign in to comment.