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

Korean future fix #40

Merged
merged 4 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/korean.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const breakdown = (input) => {
// input: array of 2 or 3 numbers representing modern jamo (components) that make up a hangul syllable
// output: a hangul character
const combineSymbols = (input) => {
const initialValue = input[0] * 588;
const medialValue = input[1] * 28;
const finalValue = input[2] ? input[2] : 0;
const total = initialValue + medialValue + finalValue + 44032;
const finalWord = String.fromCharCode(total);
return finalWord;
let unicodeTotal = (input[0] * 588) + (input[1] * 28) + 44032;
if(input.length === 3) {
unicodeTotal += input[2];
}
return String.fromCharCode(unicodeTotal);
};

class Korean {
Expand Down Expand Up @@ -129,10 +128,18 @@ class Korean {

doFuture (word) {
const stem = breakdown(word.slice(0, -1));
if (stem[-1] !== 8) {
if (stem.length < 3) {
stem.push(8);
return `${combineSymbols(stem)} 거야`;
} else {
if (stem[stem.length-1] === 17) {
stem.pop();
return `${combineSymbols(stem)}울 거야`;
} else if (stem[stem.length-1] === 8) {
return `${combineSymbols(stem)} 거야`;
}
return `${combineSymbols(stem)}을 거야`;
}
return `${combineSymbols(stem)}꺼야`;
}
} // end for class

Expand Down
48 changes: 34 additions & 14 deletions test/korean_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,48 @@ describe('Korean', () => {
});
});
describe('Future Tense', () => {
it('should conjugate regular verbs correctly', () => {
it('should conjugate verbs with stem ending with a vowel correctly', () => {
const kc = new Korean();
let presentWord = kc.conjugate('하다', {tense: 'future'});
expect(presentWord).to.equal('할꺼야');
let futureWord = kc.conjugate('하다', {tense: 'future'});
expect(futureWord).to.equal('할 거야');

presentWord = kc.conjugate('오다', {tense: 'future'});
expect(presentWord).to.equal('올꺼야');
futureWord = kc.conjugate('오다', {tense: 'future'});
expect(futureWord).to.equal('올 거야');

presentWord = kc.conjugate('비다', {tense: 'future'});
expect(presentWord).to.equal('빌꺼야');
futureWord = kc.conjugate('비다', {tense: 'future'});
expect(futureWord).to.equal('빌 거야');
});
it('should conjugate verbs with stem ending with a ㄹ consonant correctly',
() => {
const kc = new Korean();
let futureWord = kc.conjugate('놀다', {tense: 'future'});
expect(futureWord).to.equal('놀 거야');

futureWord = kc.conjugate('날다', {tense: 'future'});
expect(futureWord).to.equal('날 거야');

futureWord = kc.conjugate('울다', {tense: 'future'});
expect(futureWord).to.equal('울 거야');
});
it('should conjugate words with ㄹ final vowel correctly', () => {
it('should conjugate verbs with stem ending with ㅂ consonant correctly',
() => {
const kc = new Korean();
let presentWord = kc.conjugate('놀다', {tense: 'future'});
expect(presentWord).to.equal('놀꺼야');
let futureWord = kc.conjugate('춥다', {tense: 'future'});
expect(futureWord).to.equal('추울 거야');

presentWord = kc.conjugate('날다', {tense: 'future'});
expect(presentWord).to.equal('날꺼야');
futureWord = kc.conjugate('덥다', {tense: 'future'});
expect(futureWord).to.equal('더울 거야');
});
it('should conjugate verbs with stem ending with other consonants correctly',
() => {
const kc = new Korean();
let futureWord = kc.conjugate('있다', {tense: 'future'});
expect(futureWord).to.equal('있을 거야');

presentWord = kc.conjugate('울다', {tense: 'future'});
expect(presentWord).to.equal('울꺼야');
futureWord = kc.conjugate('먹다', {tense: 'future'});
expect(futureWord).to.equal('먹을 거야');
});

});
describe('Present Continuous Tense', () => {
it('should conjugate verbs correctly', () => {
Expand Down