Skip to content

Commit

Permalink
Merge pull request #40 from cecilebertin/KoreanFutureFix
Browse files Browse the repository at this point in the history
Korean future fix
  • Loading branch information
yjlim5 authored Apr 25, 2017
2 parents beead92 + 6c1eb3d commit e9b21fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
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 @@ -136,10 +135,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 words with ㄹ final vowel correctly', () => {
it('should conjugate verbs with stem ending with a ㄹ 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('날 거야');

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 ㅂ 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('더울 거야');
});
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('있을 거야');

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

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

0 comments on commit e9b21fb

Please sign in to comment.