-
-
Save colinjroberts/9aeae715a510627ea49426e0efe24fb6 to your computer and use it in GitHub Desktop.
korean-typing-practice-part3 - wordDecomposer.js tests
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
const wordDecomposer = require('./wordDecomposer'); | |
describe("decomposeWordsEn with EN language flag", ()=> { | |
test("decomposes (' ') into Set{}", () => { | |
let output = new Set([]) | |
expect(wordDecomposer.decomposeWordsEn(' ')).toStrictEqual(output); | |
}); | |
test("decomposes ('aabbcc') into Set{'a', 'b', 'c'}", () => { | |
let output = new Set(['a', 'b', 'c']) | |
expect(wordDecomposer.decomposeWordsEn('aabbcc')).toStrictEqual(output); | |
}); | |
test("decomposes ('a2a-아b,b=c{c') into Set{'a', 'b', 'c'}", () => { | |
let output = new Set(['a', 'b', 'c']) | |
expect(wordDecomposer.decomposeWordsEn('a2a-아b,b=c{c')).toStrictEqual(output); | |
}); | |
test("decomposes ('ᄀᄁㄴㄷ은') into Set{}", () => { | |
let output = new Set() | |
expect(wordDecomposer.decomposeWordsEn('ᄀᄁㄴㄷ은')).toStrictEqual(output); | |
}); | |
}) | |
describe("decomposeWordsKo", () => { | |
test("decomposes (' ','KO') into Set{}", () => { | |
let mapOfKoreanLettersByType = wordDecomposer.filterAndSortKoreanLetters(' ') | |
let expectedOutput = new Set() | |
let actualOutput = wordDecomposer.decomposeWordsKo(mapOfKoreanLettersByType) | |
expect(actualOutput).toStrictEqual(expectedOutput); | |
}); | |
test("decomposes ('aabbcc','KO') into Set{}", () => { | |
let mapOfKoreanLettersByType = wordDecomposer.filterAndSortKoreanLetters('aabbcc') | |
let expectedOutput = new Set() | |
let actualOutput = wordDecomposer.decomposeWordsKo(mapOfKoreanLettersByType) | |
expect(actualOutput).toStrictEqual(expectedOutput); | |
}); | |
test("decomposes ('1ᄀ2ㄷ-은,ᄁaㄴv','KO') into Set{'ㄱ', 'ㄷ', 'ㅇ', 'ㅡ', 'ㄴ', 'ㄲ'}", () => { | |
let mapOfKoreanLettersByType = wordDecomposer.filterAndSortKoreanLetters('1ᄀ2ㄷ-은,ᄁaㄴv') | |
let expectedOutput = new Set(['ㄱ', 'ㄷ', 'ㅇ', 'ㅡ', 'ㄴ', 'ㄲ']) | |
let actualOutput = wordDecomposer.decomposeWordsKo(mapOfKoreanLettersByType) | |
expect(actualOutput).toStrictEqual(expectedOutput); | |
}); | |
test("decomposes ('ᄀᄁㄴㄷ은','KO') into Set{'ㄱ', 'ㄷ', 'ㅇ', 'ㅡ', 'ㄴ', 'ㄲ'}", () => { | |
let mapOfKoreanLettersByType = wordDecomposer.filterAndSortKoreanLetters('ᄀᄁㄴㄷ은') | |
let expectedOutput = new Set(['ㄱ', 'ㄷ', 'ㅇ', 'ㅡ', 'ㄴ', 'ㄲ']) | |
let actualOutput = wordDecomposer.decomposeWordsKo(mapOfKoreanLettersByType) | |
expect(actualOutput).toStrictEqual(expectedOutput); | |
}); | |
}) | |
describe("decomposeWordsEn", () => { | |
test("decomposes '' into Set{}", () => { | |
let output = new Set([]) | |
expect(wordDecomposer.decomposeWordsEn('')).toStrictEqual(output); | |
}); | |
test("decomposes 'aabbcc' into Set{'a', 'b', 'c'}", () => { | |
let output = new Set(['a', 'b', 'c']) | |
expect(wordDecomposer.decomposeWordsEn('aabbcc')).toStrictEqual(output); | |
}); | |
test("decomposes 'a2a-b,b=c{c' into Set{'a', 'b', 'c'}", () => { | |
let output = new Set(['a', 'b', 'c']) | |
expect(wordDecomposer.decomposeWordsEn('a2a-b,b=c{c')).toStrictEqual(output); | |
}); | |
}) | |
describe("createJamoLists handles initial jamo", () => { | |
test("such that initialJamoList is [0] when given 'ㄱ'", () => { | |
let inputSet = new Set(['ㄱ']) | |
expect(wordDecomposer.createJamoLists(inputSet).initialJamoList).toStrictEqual([0]); | |
}); | |
test("such that initialJamoList is [10] when given 'ㅆ'", () => { | |
let inputSet = new Set(['ㅆ']) | |
expect(wordDecomposer.createJamoLists(inputSet).initialJamoList).toStrictEqual([10]); | |
}); | |
test("such that initialJamoList is [18] when given 'ㅎ'", () => { | |
let inputSet = new Set(['ㅎ']) | |
expect(wordDecomposer.createJamoLists(inputSet).initialJamoList).toStrictEqual([18]); | |
}); | |
test("such that initialJamoList is [0, 10, 18] when given 'ㄱ, ㅆ, ㅎ'", () => { | |
let inputSet = new Set(['ㄱ', 'ㅆ', 'ㅎ']) | |
expect(wordDecomposer.createJamoLists(inputSet).initialJamoList).toStrictEqual([0, 10, 18]); | |
}); | |
}) | |
describe("createJamoLists handles medial jamo", () => { | |
test("such that medialJamoList is [0] when given 'ㅏ'", () => { | |
let inputSet = new Set(['ㅏ']) | |
expect(wordDecomposer.createJamoLists(inputSet).medialJamoList).toStrictEqual([0]); | |
}); | |
test("such that medialJamoList is [8] when given 'ㅗ'", () => { | |
let inputSet = new Set(['ㅗ']) | |
expect(wordDecomposer.createJamoLists(inputSet).medialJamoList).toStrictEqual([8]); | |
}); | |
test("such that medialJamoList is [20] when given 'ㅣ'", () => { | |
let inputSet = new Set(['ㅣ']) | |
expect(wordDecomposer.createJamoLists(inputSet).medialJamoList).toStrictEqual([20]); | |
}); | |
test("such that medialJamoList is [0, 8, 20, 9, 11] when given 'ㅏ, ㅗ, ㅣ'", () => { | |
let inputSet = new Set(['ㅏ', 'ㅗ', 'ㅣ']) | |
expect(wordDecomposer.createJamoLists(inputSet).medialJamoList).toStrictEqual([0, 8, 20, 9, 11]); | |
}); | |
}) | |
describe("createJamoLists handles terminal jamo", () => { | |
test("such that terminalJamoList is [0, 1] when given 'ㄱ'", () => { | |
let inputSet = new Set(['ㄱ']) | |
expect(wordDecomposer.createJamoLists(inputSet).terminalJamoList).toStrictEqual([0, 1]); | |
}); | |
test("such that terminalJamoList is [0, 21] when given 'ㅇ'", () => { | |
let inputSet = new Set(['ㅇ']) | |
expect(wordDecomposer.createJamoLists(inputSet).terminalJamoList).toStrictEqual([0, 21]); | |
}); | |
test("such that terminalJamoList is [0, 27] when given 'ㅎ'", () => { | |
let inputSet = new Set(['ㅎ']) | |
expect(wordDecomposer.createJamoLists(inputSet).terminalJamoList).toStrictEqual([0, 27]); | |
}); | |
test("such that terminalJamoList is [0, 1, 21, 27] when given 'ㄱ, ㅇ, ㅎ'", () => { | |
let inputSet = new Set(['ㄱ', 'ㅇ', 'ㅎ']) | |
expect(wordDecomposer.createJamoLists(inputSet).terminalJamoList).toStrictEqual([0, 1, 21, 27]); | |
}); | |
}) | |
describe("lookupJamoKo", () => { | |
test("correctly looks up a few jamo", () => { | |
let lookup = new Map([ | |
['ᄀ', ["ㄱ"]], | |
['ᄁ', ["ㄲ"]], | |
['ᄂ', ["ㄴ"]], | |
['ᆵ', ["ㄹ", "ㅍ"]], | |
['ᇂ', ["ㅎ"]] | |
]) | |
let actualOutput = [] | |
let expectedOutput = [] | |
for (let item of lookup.keys()){ | |
actualOutput.push(wordDecomposer.lookupJamoKo(item)) | |
expectedOutput.push(lookup.get(item)) | |
} | |
expect(expectedOutput).toStrictEqual(actualOutput); | |
}); | |
}) | |
describe("filterAndSortKoreanLetters", () => { | |
test("filters out non-Korean characters", () => { | |
let result = new Map([ | |
["jamo", []], | |
["syllable", ['아']], | |
["compatibilityJamo", []] | |
]) | |
expect(wordDecomposer.filterAndSortKoreanLetters('123abc+-=아')).toStrictEqual(result) | |
}) | |
test("correctly sorts Korean initial/medial jamo, syllables, and compatibility jamo", () => { | |
let result = new Map([ | |
["jamo", ['ᄁ', 'ᄒ']], | |
["syllable", ['아']], | |
["compatibilityJamo", ['ㅈ','ㅊ']] | |
]) | |
expect(wordDecomposer.filterAndSortKoreanLetters('ᄁᄒ아ㅈㅊ')).toStrictEqual(result) | |
}) | |
}) | |
describe("decomposeKoSyllables", () => { | |
test("decomposes word with 2 letters ('아') to ['ㅇ', 'ㅏ']", () => { | |
let result = ['ㅇ', 'ㅏ'] | |
expect(wordDecomposer.decomposeKoSyllables(['아'])).toStrictEqual(result) | |
}) | |
test("decomposes word with 3 letters ('남') to [ㄴ, ㅏ, ㅁ]", () => { | |
let result = ['ㄴ', 'ㅏ', 'ㅁ'] | |
expect(wordDecomposer.decomposeKoSyllables(['남'])).toStrictEqual(result) | |
}) | |
test("decomposes word with 4 letters ('값') to ['ㄱ', 'ㅏ', 'ㅂ', 'ㅅ']", () => { | |
let result = ['ㄱ', 'ㅏ', 'ㅂ', 'ㅅ'] | |
expect(wordDecomposer.decomposeKoSyllables(['값'])).toStrictEqual(result) | |
}) | |
test("decomposes word with 3 letters and combined vowels ('쉬') to ['ㅅ', 'ㅜ', 'ㅣ']", () => { | |
let result = ['ㅅ', 'ㅜ', 'ㅣ'] | |
expect(wordDecomposer.decomposeKoSyllables(['쉬'])).toStrictEqual(result) | |
}) | |
test("decomposes word with 4 letters and combined vowels ('쉽') to ['ㅅ', 'ㅜ', 'ㅣ', 'ㅂ']", () => { | |
let result = ['ㅅ', 'ㅜ', 'ㅣ', 'ㅂ'] | |
expect(wordDecomposer.decomposeKoSyllables(['쉽'])).toStrictEqual(result) | |
}) | |
test("decomposes 2 words ('쉬' and '운') to ['ㅅ', 'ㅜ', 'ㅣ', 'ㅇ', 'ㅜ', 'ㄴ']", () => { | |
let result = ['ㅅ', 'ㅜ', 'ㅣ', 'ㅇ', 'ㅜ', 'ㄴ'] | |
expect(wordDecomposer.decomposeKoSyllables(['쉬', '운'])).toStrictEqual(result) | |
}) | |
}) | |
describe("createOneWordEn of length 8 using 'abcd'", () => { | |
let letters = "abcd" | |
let wordLength = 8 | |
let generatedWords = wordDecomposer.createOneWordEn(letters, wordLength) | |
it("contains only the provided letters", () => { | |
expect(generatedWords).toEqual(expect.stringMatching(/[abcd]/)) | |
}) | |
it("is of the correct length", () => { | |
expect(generatedWords.length).toEqual(wordLength) | |
}) | |
}) | |
describe("createOneWordKo of length 8 using 'ㄹㅎㅏ'", () => { | |
let letters = "ㄹㅎㅏ" | |
let initialList = [5, 18] | |
let medialList = [0] | |
let terminalList = [27, 8] | |
let wordLength = 8 | |
let generatedWords = wordDecomposer.createOneWordKo(initialList, medialList, terminalList, wordLength) | |
it("contains only the provided letters", () => { | |
expect(generatedWords).toEqual(expect.stringMatching(/[라랄랗할하핳]/)) | |
}) | |
it("is of the correct length", () => { | |
expect(generatedWords.length).toEqual(wordLength) | |
}) | |
}) | |
describe("getText Integration with empty string", () => { | |
it("works with English empty string", () => { | |
let expectedOutput = " " | |
let actualOutput = wordDecomposer.getText(1, '', 'EN') | |
expect(actualOutput).toStrictEqual(expectedOutput) | |
}) | |
}) | |
describe("getText Integration with space", () => { | |
it("works with English space", () => { | |
let expectedOutput = ' ' | |
let actualOutput = wordDecomposer.getText(1, ' ', 'EN') | |
expect(actualOutput).toStrictEqual(expectedOutput) | |
}) | |
}) | |
describe("getText English Integration with one letter", () => { | |
let actualOutput = wordDecomposer.getText(1, 'a', 'EN') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching(/[a]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(1) | |
}) | |
}) | |
describe("getText English Integration with one word, multiple letters", () => { | |
let actualOutput = wordDecomposer.getText(1, 'abcd', 'EN') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching( /[abcd]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(1) | |
}) | |
}) | |
describe("getText English Integration with multiple words, multiple letters", () => { | |
let actualOutput = wordDecomposer.getText(4, 'abcd', 'EN') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching(/[abcd]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(4) | |
}) | |
}) | |
describe("getText English Integration with multiple words, multiple EN and KO letters and symbols", () => { | |
let actualOutput = wordDecomposer.getText(4, 'a.bㅗ4c1d!ㄹ', 'EN') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching(/[abcd]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(4) | |
}) | |
}) | |
describe("getText Korean Integration with one word, multiple letters as compatibility jamo", () => { | |
let actualOutput = wordDecomposer.getText(1, 'ㅇㄴㅡ', 'KO') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching(/[으은응는능]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(1) | |
}) | |
}) | |
describe("getText Korean Integration with multiple words, multiple letters in one syllable", () => { | |
let actualOutput = wordDecomposer.getText(4, '은', 'KO') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching(/[으은응는능]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(4) | |
}) | |
}) | |
describe("getText Korean Integration with multiple words, multiple EN and KO letters and symbols", () => { | |
let actualOutput = wordDecomposer.getText(4, 'a.bㅗ4c1d!ㄹ', 'KO') | |
it("contains only the provided letters", () => { | |
expect(actualOutput).toEqual(expect.stringMatching(/[로롤]/)) | |
}) | |
it("is of the correct length", () => { | |
let numberOfWords = actualOutput.split(" ") | |
expect(numberOfWords.length).toEqual(4) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment