odin-default-js-exercises/pig_latin/pigLatin.spec.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-03-09 11:12:25 +00:00
const expect = require("expect");
// Topics
2017-09-20 23:04:46 +00:00
// * modules
// * strings
// Pig Latin
2021-03-09 11:12:25 +00:00
// Pig Latin is a made-up children's language that's intended to be confusing. test obeys a few simple rules (below) but when test's spoken quickly test's really difficult for non-children (and non-native speakers) to understand.
2017-09-20 23:04:46 +00:00
// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.
2021-03-09 11:12:25 +00:00
// Rule 2: If a word begins with a consonant sound, move test to the end of the word, and then add an "ay" sound to the end of the word.
2017-09-20 23:04:46 +00:00
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
// See https://en.wikipedia.org/wiki/Pig_Latin for more details.
const pigLatin = require("./pigLatin.js");
2017-09-20 23:04:46 +00:00
2021-03-09 11:12:25 +00:00
describe('translate', () => {
test('translates a word beginning with a vowel', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("apple");
2021-03-09 11:12:25 +00:00
expect(s).toBe('appleay');
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('translates a word beginning with a consonant', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("banana");
2021-03-09 11:12:25 +00:00
expect(s).toBe("ananabay");
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('translates a word beginning with two consonants', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("cherry");
2021-03-09 11:12:25 +00:00
expect(s).toBe('errychay');
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('translates two words', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("eat pie");
2021-03-09 11:12:25 +00:00
expect(s).toBe('eatay iepay');
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('translates a word beginning with three consonants', () => {
expect(pigLatin.translate("three")).toBe("eethray");
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('counts "sch" as a single phoneme', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("school");
2021-03-09 11:12:25 +00:00
expect(s).toBe("oolschay");
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('counts "qu" as a single phoneme', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("quiet");
2021-03-09 11:12:25 +00:00
expect(s).toBe("ietquay");
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("square");
2021-03-09 11:12:25 +00:00
expect(s).toBe("aresquay");
2017-09-20 23:04:46 +00:00
});
2021-03-09 11:12:25 +00:00
test.skip('translates many words', () => {
2017-09-20 23:04:46 +00:00
s = pigLatin.translate("the quick brown fox");
2021-03-09 11:12:25 +00:00
expect(s).toBe("ethay ickquay ownbray oxfay");
2017-09-20 23:04:46 +00:00
});
});